SkarpSkarp

Chapter 23 of 27

APIs, JSON, and REST: Programmatic Access to Network Devices

See how modern tools talk to network devices using structured data and web APIs, laying the groundwork for automation workflows.

27 min readen

From CLI to APIs: Why Network Engineers Care

CLI vs APIs

Historically, engineers configured devices via CLI: SSH in, type commands. Modern networks increasingly use APIs for automation, consistency, and scale.

SDN and Controllers

In SDN, controllers like Cisco DNA Center expose web-based APIs so tools and scripts can talk to the network, not just humans via CLI.

Why CCNA Cares

For CCNA, you do not need to be a programmer, but you must recognize APIs and JSON, understand REST basics, and follow the conceptual workflow.

Remote Control Analogy

CLI is like pressing buttons on the TV itself. APIs are like a universal remote that software can use to control many devices at once.

JSON: The Language of API Data

What Is JSON?

JSON (JavaScript Object Notation) is a text format for structured data. It is human-readable and machine-parseable, widely used by web and network APIs.

Objects and Arrays

JSON objects use `{ }` and contain key-value pairs. Arrays use `[ ]` and contain ordered lists of values, which can be objects, numbers, strings, etc.

Interface Example

An interface in JSON might look like: `{ "name": "GigabitEthernet1/0/1", "status": "up", "vlan": 10 }` with keys and values separated by colons.

Lists of Objects

APIs often return arrays of objects, such as a list of interfaces: `[ { "name": "Gig1/0/1" }, { "name": "Gig1/0/2" } ]`.

Hands-On: Read JSON Like a Network Engineer

Practice reading JSON that represents network objects. Focus on extracting key information you would care about as a CCNA-level engineer.

REST APIs: Canonical Definition and Core Ideas

Canonical REST Definition

A REST API is: "A Representational State Transfer (REST) API is a web-based interface that uses HTTP methods and resource-oriented URIs to enable programmatic access to network devices and controllers."

Web and HTTP

REST APIs use HTTP, like web browsers. Tools such as curl, Postman, or Python can send HTTP requests to controllers and devices.

Resources and URIs

Resources are things like devices, interfaces, clients, policies. They are addressed with URIs such as `/dna/intent/api/v1/network-device`.

HTTP Methods

Map methods to intent: GET=read, POST=create/trigger, PUT=replace, PATCH=partial update, DELETE=remove. This mapping is exam-relevant.

HTTP Methods and Resource-Oriented URIs in Practice

Resources as URLs

REST treats network objects as resources with URIs like `/api/v1/network-device` (collection) or `/api/v1/network-device/{id}` (single item).

GET Examples

`GET /api/v1/network-device` asks for all devices; `GET /api/v1/network-device/abcd-1234` asks for one specific device by ID.

Creating with POST

`POST /api/v1/vlan` with a JSON body like `{ "id": 30, "name": "GUEST-WIFI" }` requests creation of a new VLAN definition.

Updating with PATCH

`PATCH /api/v1/interface/GigabitEthernet101` plus JSON updates selected fields such as description or VLAN, not the whole resource.

Cisco DNA Center and Similar Controllers: How They Use REST

DNA Center Intent API

Cisco DNA Center offers a REST-based Intent API that lets tools discover devices, read status, and push templates or policies using HTTP and JSON.

GUI Uses the Same APIs

When you click in the DNA Center GUI, your browser is effectively calling REST endpoints like `GET /dna/intent/api/v1/network-device` behind the scenes.

Other Cisco Controllers

Meraki Dashboard and SD-WAN vManage also expose REST APIs for managing networks, devices, and policies programmatically.

Key Takeaway

Controllers centralize control and expose it via REST APIs; automation tools call these APIs using JSON instead of logging into each device individually.

Conceptual Workflow: Query and Update via a REST API

Step 1: Authenticate

First, send credentials to an auth endpoint (often via POST) and receive an access token, then include that token in Authorization headers.

Step 2: Read with GET

Use GET requests like `/network-device` or `/interface` to retrieve current state and inspect the JSON for devices, ports, and VLANs.

Step 3–4: Plan and Change

Plan modifications, encode them as JSON, then send POST/PUT/PATCH requests to create or update resources such as VLANs or interfaces.

Step 5: Verify

Finally, send GET requests again to confirm that the network state now matches your intended configuration.

Thought Exercise: Map CLI Tasks to REST Operations

Mentally translate familiar CLI tasks into REST-style operations. This builds intuition for exam scenarios and future automation work.

Quiz 1: JSON and REST Basics

Test your understanding of JSON structure and REST fundamentals.

You see the following API call in documentation: `PATCH /api/v1/interface/GigabitEthernet1_0_5` with a JSON body: ```json { "description": "Camera-01", "vlan": 30 } ``` Conceptually, what is this operation doing?

  1. Reading the current configuration of interface GigabitEthernet1/0/5
  2. Partially updating the configuration of interface GigabitEthernet1/0/5
  3. Deleting interface GigabitEthernet1/0/5 from the device
  4. Creating a brand-new physical interface on the device
Show Answer

Answer: B) Partially updating the configuration of interface GigabitEthernet1/0/5

The HTTP method is PATCH, which is commonly used for partial updates to an existing resource. The resource is the interface identified in the URI. The JSON body sets a new description and VLAN. GET would read, DELETE would remove, and you cannot create a new physical interface via an API on fixed hardware.

Quiz 2: Canonical REST Definition and Controllers

Check that you remember the canonical REST API definition and how controllers use it.

Which statement best matches the canonical definition and role of a REST API in a controller-based network?

  1. A REST API is a command-line interface that lets administrators SSH into multiple devices at once to paste configurations.
  2. A REST API is a web-based interface that uses HTTP methods and resource-oriented URIs to enable programmatic access to network devices and controllers.
  3. A REST API is a proprietary Cisco-only protocol used between switches to exchange VLAN and STP information.
  4. A REST API is a wireless security mechanism that encrypts management traffic between access points and controllers.
Show Answer

Answer: B) A REST API is a web-based interface that uses HTTP methods and resource-oriented URIs to enable programmatic access to network devices and controllers.

The correct statement is the canonical definition: "A Representational State Transfer (REST) API is a web-based interface that uses HTTP methods and resource-oriented URIs to enable programmatic access to network devices and controllers." Controllers like Cisco DNA Center expose such APIs so software can manage devices programmatically.

Key Term Flashcards: JSON, REST, and Controllers

Flip through these cards to reinforce the core concepts for the CCNA exam.

JSON object
A collection of key-value pairs enclosed in `{ }`. Keys are strings, followed by a colon and a value. Used to represent structured data such as a device, interface, or VLAN in API responses.
JSON array
An ordered list of values enclosed in `[ ]`. Often used by APIs to return lists of resources, such as multiple devices or interfaces.
REST API (canonical definition)
A Representational State Transfer (REST) API is a web-based interface that uses HTTP methods and resource-oriented URIs to enable programmatic access to network devices and controllers.
HTTP GET vs POST
GET retrieves data without changing it (read-only). POST sends data to create a new resource or trigger an action on the server, often with a JSON body.
HTTP PUT vs PATCH
PUT typically replaces an entire resource with the data provided. PATCH applies a partial update, modifying only specified fields of the resource.
Role of a controller (e.g., Cisco DNA Center)
Centralizes the control plane for many devices and exposes REST APIs so tools and scripts can discover devices, read status, and push configurations programmatically.
Typical REST workflow in networking
Authenticate to obtain a token, use GET to read current state, use POST/PUT/PATCH to change configuration, then GET again to verify the change.

Key Terms

JSON
JavaScript Object Notation, a lightweight, text-based format for representing structured data. Widely used in web and network APIs because it is easy for humans to read and for machines to parse.
REST API
A Representational State Transfer (REST) API is a web-based interface that uses HTTP methods and resource-oriented URIs to enable programmatic access to network devices and controllers.
HTTP method
The verb in an HTTP request that indicates the desired action on a resource, such as GET, POST, PUT, PATCH, or DELETE.
Access token
A credential (often a random string) issued by an API after successful authentication, included in subsequent requests to authorize access to resources.
Cisco DNA Center
A Cisco enterprise network controller that centralizes management, assurance, and automation for campus networks and exposes REST APIs (Intent APIs) for programmatic control.
Resource-oriented URI
A structured path in a REST API that identifies a resource, such as `/api/v1/network-device` for devices or `/api/v1/interface` for interfaces.
Controller-based networking
An approach where a central controller manages many network devices, often using SDN principles and exposing programmable APIs instead of configuring each device individually via CLI.

Finished reading?

Test your understanding with a custom practice exam on this chapter.

Test yourself