Everything the interface does is a call
The Manager web interface is a client of the Manager API. Anything you can click, such as listing devices, reading alarms or attaching a template, is a request to a path under /dataservice that returns JSON. Automation uses the same calls, so learning the shape of the API also explains what the interface does for you.
The client logs in and receives a session cookie, fetches a token for calls that change things, sends requests, reads the JSON replies, and logs out.
- Log incredentials sent,cookie returned
- Tokenfetched forwrite calls
- Requestmethod, path,headers, body
- Responsestatus codeand JSON
- Log outend thesession
The parts of a call
Every call has the same parts. The method says what to do, the path says to what, the headers carry the session and the data format, and a body carries the data for calls that create or change something. Reading a call by its parts makes an unfamiliar one easy to follow.
| Part | Example | Notes |
|---|---|---|
| Method | GET, POST, PUT, DELETE | GET only reads; the others change state |
| Address | https://manager.example.com | The Manager, over HTTPS with a trusted certificate |
| Path | /dataservice/device | Names the thing; differs between releases |
| Session | Cookie with the session id | Issued at login; expires after a period |
| Token | X-XSRF-TOKEN header | Required by many releases for write calls |
| Body and format | JSON with Content-Type: application/json | Only for calls that send data |
Read calls and write calls
A GET call changes nothing, so it is the right place to start and the right tool for inventory and reports. POST, PUT and DELETE calls change the fabric, and a single one can affect many devices, for example by attaching a template or activating a policy. Treat the two groups differently in every script.
Read calls use GET and only return data, so they are safe to repeat. Write calls use POST, PUT or DELETE and change the fabric, so they need a lab test, a backup and a check of the response.
Read the current state, test the call on a lab Manager, take a backup, send one call, and check the response and the result.
- Readcurrent statesaved to a file
- Labsame call on alab Manager
- BackupManager backupand a rollback
- One calla single call,not a loop
- Checkstatus, bodyand the result
A first script: log in and read the inventory
Three steps are enough for a first read. Log in and keep the session cookie, fetch a token if your release uses one, and call the device inventory. The commands below keep the credentials in environment variables rather than in the command or the file, and the address is a placeholder.
curl -s -c cookies.txt -X POST https://manager.example.com/j_security_check -d "j_username=$SDWAN_USER" -d "j_password=$SDWAN_PASS"Logs in and stores the session cookie in cookies.txt. Use a trusted certificate on the Manager; an option that skips certificate checks is for a lab only. Check the release's guide, since the login path and the cookie handling can change.
curl -s -b cookies.txt https://manager.example.com/dataservice/client/tokenFetches the token that many releases require in the X-XSRF-TOKEN header for write calls. A read call does not need it, so skip this step for a read-only script.
curl -s -b cookies.txt https://manager.example.com/dataservice/deviceReads the device inventory as JSON. Pipe it through a JSON formatter to read it, and keep the file as a record of the fabric on that date.
$curl -s -b cookies.txt https://manager.example.com/dataservice/device { "data": [ { "host-name": "BR-01", "system-ip": "10.255.1.11", "reachability": "reachable" }, { "host-name": "BR-02", "system-ip": "10.255.1.12", "reachability": "unreachable" } ] }
| Devices | One inventory call every 5 minutes | One call per device every 5 minutes | Extra requests |
|---|---|---|---|
| 50 | 12 | 600 | 588 |
| 200 | 12 | 2,400 | 2,388 |
| 500 | 12 | 6,000 | 5,988 |
One authenticated inventory read can feed a reachability report, a software version report and a record of sites and system addresses.
- Reachabilitydevices thatare not up
- Versionssoftware bydevice
- Sitesnames, IDs andsystem IPs
- Recorddated filefor audits
A worked case: status 200 and no JSON
A new script reports success, yet the report is empty. The device call returned status 200, so nothing looks wrong. The response body is the clue.
$curl -s -b cookies.txt https://manager.example.com/dataservice/device | head -c 120 <html><head><title>Login</title></head><body><form action="/j_security_check" method="post">
The call returned status 200, the body is a login page, the cookie file holds no valid session, and the login step had been checked only by its status.
- Status200, which looks fineA login page is also a page
- BodyHTML login formNot the JSON that was expected
- SessionCookie rejected or expiredNo valid session to reuse
- FixCheck the login reply, not only its statusLog in again when a reply is not JSON
Reading the HTTP status
| Status | Meaning | First check |
|---|---|---|
| 200 | The request was served | Is the body JSON? A login page is also served with 200 |
| 401 or 403 | Not authenticated, or not allowed | Session cookie, token header and the account's role |
| 404 | No such path | The path for your release in the Manager's API documentation |
| 400 | The request body or a field is wrong | JSON syntax, field names and the Content-Type header |
| 429 or 5xx | Too many requests, or the Manager is busy | Slow the script, wait and retry with a delay |
| Retry | Wait before it | Total waited so far |
|---|---|---|
| 1 | 1 second | 1 second |
| 2 | 2 seconds | 3 seconds |
| 3 | 4 seconds | 7 seconds |
| 4 | 8 seconds | 15 seconds |
| 5 | 16 seconds | 31 seconds |
Learn more: SD-WAN Manager WorkflowsBackup and Lifecycle ManagementSD-WAN Root-Cause Framework
Test yourself
A script calls the device inventory, gets status 200, and the body starts with an HTML login form. What is wrong?
Which call is the safest first step for a new script?
Where should the account password for a script be kept?
A call returns 404. What is the first check?
A script polls 200 devices with one call per device every 5 minutes. How many requests does it send in an hour?
A script retries after a 429, waiting 1 second, then 2, 4, 8 and 16. How long has it waited in total after the fifth retry?
What comes first before a script sends a write call to a production Manager?