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
- 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.
| Item | Value |
|---|---|
| Workstation | devbox (Ubuntu desktop over RDP), files in ~/lab |
| KNC API | http://127.0.0.1:8080/api/v1 (plain HTTP on the loopback only, so you can watch everything) |
| Credentials | netops / 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
- Start the controller and read its documentation
- Get a token with curl, use it, and break it on purpose
- Use an API key
- Build the client: log in and send requests
- Read every page
- Respect rate limits and recover from expired tokens
- Use an asynchronous job
- 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.
| Node | Device | Image in Add Node | Set to |
|---|---|---|---|
| devbox | EVE-NG GUI server (Docker) | eve-gui-server:latest | 1 vCPU, 1,024 MB |
How to open this lab
Sign in to your workspace at
lab.cloudlabbox.com.In File Manager, open Shared, then the folder
Network Automation - CCNA and CCNP Automation guided labs.Open
05 - Controller-style REST APIs - tokens API keys pagination rate limits and webhooksand 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
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.