Use it when calling a device or controller API, or when an API call returns an error.
JSON & REST APIs
1. curl -i the URL — which status code?
2. 401 → authentication (token expired, wrong header); 403 → permissions.
3. 404 → URL or resource path wrong.
4. 400/415 → body is not valid JSON or wrong Content-Type; validate with jq.
5. Success → read the resource back to confirm the change.
source of truth → data validated → API or tool authenticated → change applied idempotently → state read back → matches intent
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common failure patterns Narrow the fault
Common faults include malformed data, wrong URI/method, authentication, non-idempotent logic or assuming API success shows network-state success.
Step 2 Common mistakes Narrow the fault
- Sending JSON with the wrong
Content-Typeheader. - Parsing API responses without checking the HTTP status code first.
- Hard-coding credentials in scripts.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
JSON: objects {"key": value}, arrays [ ], strings in double quotes, no trailing commas. Status codes: 2xx success, 4xx client error (400 bad body, 401 not authenticated, 403 not allowed, 404 wrong URL), 5xx server error. Send Content-Type and Accept headers that match the API.
curl -sk -u <user>:<pw> -H 'Accept: application/yang-data+json' https://<device>/restconf/data/ietf-interfaces:interfaces— RESTCONF read.curl -i— HTTP status code and headers (200 OK, 201 Created, 204 No Content, 400, 401, 403, 404).python3 -m json.tool < file.json/jq . file.json— JSON valid and readable.show netconf-yang status/show platform software yang-management process— device API agents running.show ip http server status— HTTPS server for RESTCONF.
ReferenceWhat it is1 section · depth on demand
Concept overview
JSON structures, REST methods and API fundamentals.
Foundation focus: Model data first, then API/controller workflow, then automation logic and validation.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
JSON and REST APIs in practice
Most network APIs exchange JSON over HTTPS. Both sides need to agree on the data format and the HTTP semantics. RFC 8259 is strict about JSON:
- Strings in double quotes, and lowercase
true,falseandnull. - No leading zeros, and no NaN or Infinity.
- Names should be unique within an object.
- Text exchanged between systems must be UTF-8, with the media type
application/json. - No comment syntax.
Mapping network data to JSON
| Network concept | JSON form |
|---|---|
| A device | Object: {"hostname": "acc-2f-01", "mgmtIp": "10.255.1.21"} |
| An inventory | Array of objects |
| A VLAN list | Array of numbers: [110, 120, 999] |
| An interface state | Object with string or boolean values: {"name": "Gi1/0/14", "enabled": true} |
| Missing data | null, or the field left out (APIs differ) |
Request and response basics
| Element | Example |
|---|---|
| Method | GET (read), POST (create), PUT (replace), PATCH (modify), DELETE |
| URI | /api/v1/devices/{id} |
| Headers | Content-Type: application/json, Accept: application/json, an authentication header |
| Body | A JSON object for POST, PUT and PATCH |
| Status | 2xx success, 4xx client error, 5xx server error |
Parsing safely
| Practice | Reason |
|---|---|
| Check the status code before parsing | Error bodies may not be JSON |
| Use a JSON library, not string matching | Order and whitespace are not significant |
Handle missing keys (.get(), jq '.x // empty') | Fields vary between versions |
| Paginate | Large collections are returned in pages |
dev$ curl -s -H "Accept: application/json" -H "X-Auth-Token: $TOKEN" https://catc.example.net/dna/intent/api/v1/network-device?limit=2 | jq '.response[] | {hostname, managementIpAddress, reachabilityStatus}'
{
"hostname": "acc-2f-01",
"managementIpAddress": "10.255.1.21",
"reachabilityStatus": "Reachable"
}
dev$ python3 -c "import json; json.loads('{\"vlans\": [110, 120,]}')"
json.decoder.JSONDecodeError: Expecting value: line 1 column 20 (char 19)
dev$ echo '{"vlan": 0110}' | python3 -m json.tool
Expecting ',' delimiter: line 1 column 12 (char 11)
The last two examples show what RFC 8259 rejects: trailing commas and leading zeros. Both are common mistakes in hand-written payloads.
Documented example, not captured output.
Quick reference
A REST API lets software manage a system over HTTP using the same basic operations everywhere: read, create, replace, update and delete. Each resource has a URL, data is exchanged as JSON, and HTTP status codes report the outcome. Once these conventions are understood, working with any REST-based controller or device API follows the same pattern.
REST APIs use HTTP methods on resources and exchange JSON:
| Method | Use | Typical code |
|---|---|---|
| GET | Read | 200 |
| POST | Create/act | 201/202 |
| PUT | Replace | 200/204 |
| PATCH | Partial update | 200/204 |
| DELETE | Remove | 204 |
curl -s -H 'Accept: application/yang-data+json' -u admin:… \
https://10.0.0.1/restconf/data/ietf-interfaces:interfaces
Errors: 400 bad request, 401 not authenticated, 403 forbidden, 404 not found, 409 conflict, 429 rate limited, 5xx server error.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Automation & Programmability → JSON & REST APIs. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.cisco.com/c/en/us/support/ios-nx-os-software/ios-xe-17/series.html · confidence 94%