cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2949
Views
0
Helpful
2
Replies

Cisco DNA-C REST API non JSON return

wfrans
Level 1
Level 1

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?


1 Accepted Solution

Accepted Solutions

jeffandiorio
Level 1
Level 1

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)

View solution in original post

2 Replies 2

jeffandiorio
Level 1
Level 1

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)

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.

Review Cisco Networking for a $25 gift card