nerdexam
Cisco

200-901 · Question #439

Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing to obtain an authorization token by using the Cisco DNA Center API. Not all options are used…

The correct answer is auth/token; POST; HTTPBasicAuth; response. The question requires filling in missing Python code to authenticate with Cisco DNA Center API using basic authentication and retrieve an authorization token via a POST request to the /api/system/v1/auth/token endpoint.

Understanding and Using APIs

Question

Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing to obtain an authorization token by using the Cisco DNA Center API. Not all options are used. Answer:

Exhibit

200-901 question #439 exhibit

Answer Area

Drag items

tokenauth/tokenresponserequestHTTPBasicAuthHTTPTokenAuthPOST

Correct arrangement

  • auth/token
  • POST
  • HTTPBasicAuth
  • response

Explanation

The question requires filling in missing Python code to authenticate with Cisco DNA Center API using basic authentication and retrieve an authorization token via a POST request to the /api/system/v1/auth/token endpoint.

Approach. 1. The first blank in the url definition is to complete the API endpoint. The standard Cisco DNA Center API endpoint for obtaining an authorization token is /api/system/v1/auth/token. Therefore, auth/token is the correct option to complete the URL path. 2. The second blank is for the HTTP method used in requests.request(). To generate or obtain a new authorization token by providing credentials, a POST request is the standard and correct HTTP method, as it typically involves creating a new session or resource (the token). 3. The third blank specifies the auth mechanism for requests.request(). Since the function is called with (username, password), HTTPBasicAuth is the appropriate method to send these credentials in the request header for the initial authentication process. 4. The fourth blank in the return statement expects an object that has a .json() method and can be indexed with ['Token']. The requests.request() call stores its resulting requests.Response object in the response variable. This response object contains the API's JSON payload and is the correct object to call .json() on to extract the token value.

Common mistakes.

  • common_mistake. 1. Dragging token to the URL path is incorrect because token is the value being retrieved, not the path segment to the endpoint. auth/token is the correct endpoint component.
  1. Using request in the return statement is wrong because requests.request is the function used to make the call, not the object containing the API's response. The response variable holds the actual requests.Response object.
  2. Choosing HTTPTokenAuth is incorrect for this step because HTTPTokenAuth is used for sending an already obtained token for authentication in subsequent API calls, not for the initial authentication using username and password to get the token.
  3. Using an HTTP GET method instead of POST would be incorrect for generating a new token. GET is for retrieving data, while POST is for sending data to create or update a resource, which is what obtaining a token effectively is.

Concept tested. Cisco DNA Center API authentication workflow, understanding of REST API principles (HTTP methods, endpoints), proficiency in using the Python requests library for HTTP requests, knowledge of HTTP Basic Authentication, and JSON response parsing.

Topics

#Cisco DNA Center API#API Authentication#Authorization Token#REST API

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice