Interaction with Cisco DNA Center API

5.3.b i HTTP request (GET, PUT, POST) via Python requests library and Postman

General information on “DNAC via Python requests library and Postman”:

Basic DNAC authentication + GET via Python w/ requests library (example):

## IMPORT requests AND json MODULE
import requests
import json


## FUNCTION TO REQUEST A DNAC TOKEN
def get_dnac_token():
    url = 'https://sandboxdnac.cisco.com/dna/system/api/v1/auth/token'
    auth_user = 'devnetuser'
    auth_pass = 'Cisco123!'
    headers = {'Content-Type': 'application/json'}

    get_dnac_token = requests.post(url,
                                   auth=(auth_user, auth_pass),
                                   headers=headers,
                                   verify=False)
    get_dnac_token_RETURN = get_dnac_token.json()['Token']

    return get_dnac_token_RETURN


## FUNCTION TO GET DNAC SITE DATA
def get_dnac_site(token):
    url = 'https://sandboxdnac.cisco.com/dna/intent/api/v1/site'
    headers = {'x-auth-token': token, 'Content-Type': 'application/json'}

    get_dnac_site = requests.get(url,
                                 headers=headers,
                                 verify=False)

    return get_dnac_site_RETURN


## GET DNAC TOKEN via FUNCTION
dnac_token = get_dnac_token()


## GET DNAC SITES via FUNCTION
dnac_sites = get_dnac_site(dnac_token)