Pcornel
Browse topics
Options
Recent
Favorites
Networking · Technical reference

JSON & REST APIs

Direct answer

REST APIs expose resources at URLs and act on them with HTTP methods — GET reads, POST creates, PUT replaces, PATCH changes part, DELETE removes — usually exchanging JSON. Status codes report the result.

When to use this

Use it when calling a device or controller API, or when an API call returns an error.

First 30 seconds

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.

Operational verification

source of truth → data validated → API or tool authenticated → change applied idempotently → state read back → matches intent

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Cisco IOS / IOS XE
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformCisco IOS / IOS XE
Scope / prerequisiteUse it when calling a device or controller API, or when an API call returns an error.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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-Type header.
  • Parsing API responses without checking the HTTP status code first.
  • Hard-coding credentials in scripts.
Evidence references

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.

observation · 1
Command lookup Jump straight to Cisco syntax
Key points

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.

Key checks
  • 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, false and null.
  • 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 conceptJSON form
A deviceObject: {"hostname": "acc-2f-01", "mgmtIp": "10.255.1.21"}
An inventoryArray of objects
A VLAN listArray of numbers: [110, 120, 999]
An interface stateObject with string or boolean values: {"name": "Gi1/0/14", "enabled": true}
Missing datanull, or the field left out (APIs differ)

Request and response basics

ElementExample
MethodGET (read), POST (create), PUT (replace), PATCH (modify), DELETE
URI/api/v1/devices/{id}
HeadersContent-Type: application/json, Accept: application/json, an authentication header
BodyA JSON object for POST, PUT and PATCH
Status2xx success, 4xx client error, 5xx server error

Parsing safely

PracticeReason
Check the status code before parsingError bodies may not be JSON
Use a JSON library, not string matchingOrder and whitespace are not significant
Handle missing keys (.get(), jq '.x // empty')Fields vary between versions
PaginateLarge 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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:

MethodUseTypical code
GETRead200
POSTCreate/act201/202
PUTReplace200/204
PATCHPartial update200/204
DELETERemove204
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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docCisco IOS / IOS XE Current documentation reviewed 2026-09-14

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%
Confirmation

Confirm action

Continue?