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.
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
Answer Area
Drag items
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
tokento the URL path is incorrect becausetokenis the value being retrieved, not the path segment to the endpoint.auth/tokenis the correct endpoint component.
- Using
requestin the return statement is wrong becauserequests.requestis the function used to make the call, not the object containing the API's response. Theresponsevariable holds the actualrequests.Responseobject. - Choosing
HTTPTokenAuthis incorrect for this step becauseHTTPTokenAuthis 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. - Using an HTTP
GETmethod instead ofPOSTwould be incorrect for generating a new token.GETis for retrieving data, whilePOSTis 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
Community Discussion
No community discussion yet for this question.
