04-05-2018 01:53 AM - edited 03-08-2019 05:26 PM
Hi all,
I have an issue with the REST-API interface, the DNA-C returns in HTTP in stead of JSON. I already tried the header with Content-Type:application/json and Accept:application/json. Authentication/Authorization is ok, I receive a token. But this also return HTML in stead of JSON.
What am I doing wrong?
Solved! Go to Solution.
04-05-2018 05:06 AM
Can you share the code you are using to access the API?
I have used postman and the https://dnac/dna/apitester to learn the api. Here is a basic access to access the device inventory and represent as json.
import requests
import json
from pprint import pprint
import sys
username = sys.argv[1]
password = sys.argv[2]
hostname = sys.argv[3]
login_url = 'https://{}/api/system/v1/auth/login'.format(hostname)
session = requests.session()
session.auth = username, password
session.verify = False
login_results = session.get(login_url)
session.headers.update({'cookie':login_results.headers['Set-Cookie']})
session.headers.update({'content-type':'application/json'})
devices_url = 'https://{}/api/v1/network-device'.format(hostname)
device_results = session.get(devices_url)
devices = device_results.json()
pprint(devices)
04-05-2018 05:06 AM
Can you share the code you are using to access the API?
I have used postman and the https://dnac/dna/apitester to learn the api. Here is a basic access to access the device inventory and represent as json.
import requests
import json
from pprint import pprint
import sys
username = sys.argv[1]
password = sys.argv[2]
hostname = sys.argv[3]
login_url = 'https://{}/api/system/v1/auth/login'.format(hostname)
session = requests.session()
session.auth = username, password
session.verify = False
login_results = session.get(login_url)
session.headers.update({'cookie':login_results.headers['Set-Cookie']})
session.headers.update({'content-type':'application/json'})
devices_url = 'https://{}/api/v1/network-device'.format(hostname)
device_results = session.get(devices_url)
devices = device_results.json()
pprint(devices)
04-05-2018 06:05 AM
Thanks, this solved my issue, I used an incorrect URL.
The docs on https://developer.cisco.com/site/dna-center-rest-api/ state /global-credential as a path. I missed the /api/v1 part.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide