cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Ask the Expert- SD-WAN

843
Views
0
Helpful
2
Replies
Highlighted
Beginner

Cisco DNA-C REST API non JSON return

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?


Everyone's tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Beginner

Re: Cisco DNA-C REST API non JSON return

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)

2 REPLIES 2
Beginner

Re: Cisco DNA-C REST API non JSON return

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)

Beginner

Re: Cisco DNA-C REST API non JSON return

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.

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards