Automation and Artificial Intelligence · Topic 4 of 7
Catalyst Center and SD-WAN Manager APIs
Describe the REST APIs of Cisco Catalyst Center and SD-WAN Manager: authentication, the Intent API, the dataservice path, tokens and Python calls.
- 5 min
- Both controllers offer REST APIs over HTTPS, with JSON replies.
- Catalyst Center Intent API paths start with
/dna/intent/api/. - Catalyst Center issues a token from
/dna/system/api/v1/auth/token, using basic authentication.
What it is
Catalyst Center and SD-WAN Manager both expose REST APIs, so scripts and other tools can do what the graphical interface does.
An API call is an HTTPS request to a path on the controller, and the answer comes back as JSON. Because the controller manages many devices, one API call can read or change a whole network. Both controllers use token or session based login, and both are described by documentation on the controller itself.
How it works
Each controller has its own login method, path layout and data format.
Catalyst Center APIs
Catalyst Center offers several groups of API.
| API group | Purpose |
|---|---|
| Intent API | Northbound REST calls for network settings, sites, devices, clients and more |
| Integration API | Events and notifications, and links to other systems such as ticketing |
| Other API groups | Further groups exist, such as device management and multivendor support, and they vary by release |
The Intent API is the one that you use most. Paths for it start with /dna/intent/api/, followed by a version.
Catalyst Center authentication
A client logs in once, receives a token, and sends the token on later calls.
POST /dna/system/api/v1/auth/token HTTP/1.1
Host: catalyst.example
Authorization: Basic BASE64OFUSERNAMEANDPASSWORD
The reply holds a token. The client then adds it to a header named X-Auth-Token.
GET /dna/intent/api/v1/network-device HTTP/1.1
Host: catalyst.example
X-Auth-Token: TOKENVALUE
Accept: application/json
The reply is a JSON object with a response key that holds a list of devices, and a version key. Each device entry has fields such as the host name, the management address, the platform and the software version.
{
"response": [
{
"hostname": "sw1.example",
"managementIpAddress": "10.1.1.11",
"platformId": "C9300-24P",
"softwareVersion": "17.9.4",
"reachabilityStatus": "Reachable"
}
],
"version": "1.0"
}
Some calls run a task in the background. In that case the controller answers at once with a task identifier, and the client asks for the task status until it is finished.
Catalyst Center in Python
import requests
from urllib.parse import urlunsplit
HOST = "catalyst.example"
auth_url = urlunsplit(("https", HOST, "/dna/system/api/v1/auth/token", "", ""))
reply = requests.post(auth_url, auth=("admin", "PASSWORD"), verify=False)
token = reply.json()["Token"]
dev_url = urlunsplit(("https", HOST, "/dna/intent/api/v1/network-device", "", ""))
devices = requests.get(dev_url, headers={"X-Auth-Token": token}, verify=False)
for d in devices.json()["response"]:
print(d["hostname"], d["managementIpAddress"])
The script gets a token with basic authentication. It then calls the device list with the token in the header, and prints two fields from each device. A Python software development kit exists as well, so you can call functions instead of building URLs.
SD-WAN Manager APIs
SD-WAN Manager has a REST API under the path /dataservice. The Manager documents its calls in an API reference that is available on the Manager itself.
Login uses a session. The client posts a user name and password as form data to /j_security_check, and receives a session cookie. On current releases a second step is needed for calls that change data: the client asks /dataservice/client/token for a token and sends it in a header named X-XSRF-TOKEN.
POST /j_security_check HTTP/1.1
Content-Type: application/x-www-form-urlencoded
j_username=admin&j_password=PASSWORD
Once logged in, the client can read data.
GET /dataservice/device HTTP/1.1
Host: manager.example
Cookie: JSESSIONID=SESSIONVALUE
The reply is JSON with a data key that holds a list of devices, such as controllers and edge routers.
Python and a session
A requests session keeps the cookie for you.
import requests
from urllib.parse import urlunsplit
HOST = "manager.example"
s = requests.Session()
login_url = urlunsplit(("https", HOST, "/j_security_check", "", ""))
s.post(login_url, data={"j_username": "admin", "j_password": "PASSWORD"}, verify=False)
dev_url = urlunsplit(("https", HOST, "/dataservice/device", "", ""))
reply = s.get(dev_url, verify=False)
for d in reply.json()["data"]:
print(d["host-name"], d["system-ip"])
Comparing the two
| Feature | Catalyst Center | SD-WAN Manager |
|---|---|---|
| Base path | /dna/intent/api/ | /dataservice/ |
| Login | Token from /dna/system/api/v1/auth/token | Session cookie from /j_security_check |
| Header after login | X-Auth-Token | Session cookie, plus X-XSRF-TOKEN for changes |
| Reply wrapper | response | data |
| Format | JSON | JSON |
What to remember for the exam
Eight facts cover most questions on this topic.
- Both controllers offer REST APIs over HTTPS, with JSON replies.
- Catalyst Center Intent API paths start with
/dna/intent/api/. - Catalyst Center issues a token from
/dna/system/api/v1/auth/token, using basic authentication. - The token goes in the
X-Auth-Tokenheader on later calls. - A Catalyst Center list reply holds its items under the
responsekey. - SD-WAN Manager paths start with
/dataservice. - SD-WAN Manager login uses
/j_security_checkand a session cookie. - An SD-WAN Manager list reply holds its items under the
datakey.
To tell the two apart, remember that Catalyst Center uses a token header, and SD-WAN Manager uses a session cookie.
Common mistakes
These four mistakes appear often.
Sending the token in the wrong header. Catalyst Center expects X-Auth-Token.
Forgetting basic authentication on the token request. The token call needs credentials.
Reading the wrong key in the reply. Catalyst Center uses response, and SD-WAN Manager uses data.
Expecting an instant result from a task. Some calls return a task identifier first.
Do not leave credentials in scripts. Read them from the environment or a protected store.
Check yourself
Work through these three questions.
Which header carries the token on Catalyst Center calls?
The
X-Auth-Tokenheader.How does a client log in to SD-WAN Manager?
It posts a user name and password to
/j_security_checkand receives a session cookie.Under which key does a Catalyst Center list reply hold its items?
Under the
responsekey.
Topic 4 of 7 in Automation and Artificial Intelligence
Test yourself on Automation and Artificial Intelligence
The full Cisco CCNP 350-401 ENCOR question bank has 854 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Cisco. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.