Draft — in editorial review, not yet published. Content has not been approved by a human reviewer.
Lesson 15 / 50 · Version 2.2.0
REST APIs and Pagination
- Level
- Beginner–Intermediate
- Duration
- 15 min learn + 15 min apply
- Prerequisites:
- Lesson 11
Why it matters: When a no-code module doesn't exist, or you need volume, you call the API directly. Reading an API contract, handling errors, and paginating correctly are the skills behind every serious integration.
By the end you can:
- Read an HTTP request and response
- Interpret common status codes
- Paginate completely and resumably
- React properly to rate limits
Learn (15 min)
1. Request and response (5 min)
GET /v1/contacts?limit=100 HTTP/1.1
Host: api.example.com
Authorization: Bearer <token>
Accept: application/json
→ 200 OK
{ "results": [ ... 100 contacts ... ], "next": "cursor_8f3a" }
Parts: method (GET reads, POST creates/triggers actions, PUT/PATCH update, DELETE removes; follow the provider's documentation), URL, headers, optional body; response has status, headers, and body.
2. Authentication and errors (5 min)
Credentials go in headers or client libraries, not URLs or logs. Know the families:
| Status | Usually means | Reaction |
|---|---|---|
| 200/201 | Success | Verify the result |
| 400/422 | Bad or invalid input | Fix input; don't blindly retry |
| 401 | Missing/invalid credentials | Re-authenticate |
| 403 | Not permitted | Fix permissions/scopes |
| 404 | Not found | Check ID; treat as data issue |
| 429 | Rate limited | Wait per Retry-After/guidance |
| 5xx | Server problem | Retry with backoff (bounded) |
3. Pagination and rate limits (5 min)
APIs return results in pages. Follow the exact next cursor/URL until the API signals completion; don't construct opaque cursors. Save progress so a failed job can resume.
cursor = load_checkpoint() or None
while True:
page = GET /contacts?limit=100&cursor=cursor
upsert(page.results) # idempotent by contact id
save_checkpoint(page.next)
if not page.next: break
respect_rate_limit()
Apply (15 min)
Worked example (3 min). Import 12,000 contacts at 100/page = 120 requests. Plan: upsert by stable ID (no duplicates on re-run), checkpoint after each page, if 429 then wait the indicated time and retry the same page, final check compares the destination count to the source total and spot-checks 20 records.
Lab (7 min): Read a real API.
- Open any public API documentation (a weather or public-data API works) and find: base URL, authentication, one list endpoint, pagination method, rate limit.
- Write the request you'd send for page 2 using the documented method.
- List what you'd do on a 401, a 429, and a 500.
Deliverable: A "contract summary" table plus three error reactions. You're done when: Someone else could write the loop from your summary.
Check yourself (5 min)
- Four parts of an HTTP request?
- What does 401 generally mean? 403?
- Scenario: Your import stops at page 37 after a timeout. How do you resume without duplicates?
- How should an opaque cursor be handled?
- Safe reaction to a 429?
Reference
Common mistakes
| Symptom | Likely cause | Fix |
|---|---|---|
| Missing records | Stopped after first page | Loop to the documented end |
| Duplicates after retry | Create instead of upsert | Upsert by stable ID |
| Banned/throttled | Hammering after 429 | Backoff and respect Retry-After |
Cheat sheet: Read contract → authenticate → request page → process idempotently → checkpoint → follow returned cursor → stop at the documented end.
Key terms: HTTP method, status code, header, cursor, rate limit, upsert.
Interview prompts: How do you design a resumable import? How do you handle rate limits across parallel workers?
Go deeper: MDN HTTP overview · GET method · Microsoft pagination example · n8n rate-limit handling
Next: Lesson 16 — webhooks, APIs in reverse.