Network automation lab 5 of 27

Controller-style REST APIs: tokens, API keys, pagination, rate limits and webhooks

Write a Python client for a controller-style REST API that handles token and API-key authentication, every page of a paginated list, 429 rate limits, expired tokens, an asynchronous job and signed webhooks.

Run this lab

It needs Lite: its 1 node is set to 1 vCPU and 1,024 MB in total. That fits the free demo too.

In your workspace: Shared, then Network Automation - CCNA and CCNP Automation guided labs, then 05 - Controller-style REST APIs - tokens API keys pagination rate limits and webhooks

Try it free for 30 minutesRun it on Lite from £3 a day

The free demo needs no card and no email. Every lab plan includes every guided lab.

Level
Beginner
Time
About 75 minutes
Nodes need
1 vCPU, 1,024 MB
Smallest plan
Lite

The scenario

Kestrel Freight is buying a network controller for its five sites. The controller's northbound REST API will feed the team's inventory reports, ticketing and alerting, so before it arrives you are writing the Python client against KNC, a small mock controller that runs on your workstation. KNC behaves the way controller APIs behave in real life: you swap credentials for a short-lived token, some calls need an API key instead, lists come back one page at a time, you get throttled if you're greedy, long jobs run in the background, and the controller pushes events to you with signed webhooks.

ItemValue
Workstationdevbox (Ubuntu desktop over RDP), files in ~/lab
KNC APIhttp://127.0.0.1:8080/api/v1 (plain HTTP on the loopback only, so you can watch everything)
Credentialsnetops / the lab password, already in the environment as $NET_USER and $NET_PASS
API key~/lab/knc/api_key.txt
Documentation~/lab/knc/API.md
Your code~/lab/knc_client.py (starter with TODOs) and ~/lab/webhook_receiver.py

Topology: one workstation; KNC and your webhook receiver both run on it.

What you’ll practise

  • Construct REST requests from API documentation with curl and Python requests
  • Authenticate with HTTP Basic, a short-lived token and an API key, and explain the difference
  • Read every page of a paginated list by following Link headers
  • Handle 401, 404, 400, 415 and 429 responses correctly, including Retry-After and token renewal
  • Use an asynchronous API (202 Accepted and polling) and receive webhooks with HMAC signature checks

The tasks

  1. Start the controller and read its documentation
  2. Get a token with curl, use it, and break it on purpose
  3. Use an API key
  4. Build the client: log in and send requests
  5. Read every page
  6. Respect rate limits and recover from expired tokens
  7. Use an asynchronous job
  8. Receive webhooks safely

The Lab Tasks pane has the scenario, these tasks, the checks to run, hints and the full solution.

Topology and devices

The network as it opens in EVE-NG, drawn from the lab’s own canvas, and the image each node runs.

Topology of Controller-style REST APIs - tokens API keys pagination rate limits and webhooks1 node, 0 links. Every link is listed as text below the diagram.devbox
1 node, with the interface names each link uses.
Nodes in Controller-style REST APIs: tokens, API keys, pagination, rate limits and webhooks, with the image each runs and the vCPU and RAM it’s set to
NodeDeviceImage in Add NodeSet to
devboxEVE-NG GUI server (Docker)eve-gui-server:latest1 vCPU, 1,024 MB

How to open this lab

  1. Sign in to your workspace at lab.cloudlabbox.com.

  2. In File Manager, open Shared, then the folder Network Automation - CCNA and CCNP Automation guided labs.

  3. Open 05 - Controller-style REST APIs - tokens API keys pagination rate limits and webhooks and start its nodes, then open Lab Tasks for the scenario and the steps.

The lab is read-only. You can start the nodes and configure the devices, but changes to the topology can’t be saved. To change it, rebuild it in your own folder.

More Network automation labs

All Network automation labs

Related labs in other courses

CloudLabBox is independent of Cisco. The lab follows exam topics and isn’t vendor training material; vendor names identify the exams and the images in the workspace.