QuestionQ39

VerifiedUnderstanding and Using APIs

Drag the code choices from the bottom into the missing-code boxes to authenticate to the Cisco DNA Center REST API with basic authentication, then generate a token for later use. Not every option is needed.

Drag & Drop
import requests
from requests.auth import HTTPBasicAuth

BASE_URL = 'https://sandboxdnac2.cisco.com'
AUTH_URL = '/dna/system/api/v1/'
USERNAME = 'admin'
PASSWORD = 'qwer1234!'

response = requests.(BASE_URL + AUTH_URL,
    auth=HTTPBasicAuth(, ))
token = response.json()['Token']
print(token)
Explanation

Cisco Catalyst Center uses POST /dna/system/api/v1/auth/token to generate an access token. The request supplies credentials using HTTP Basic Authentication, whose arguments are the username and password; the returned JSON token is read from the Token field.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!