Session 4 / 15๐Ÿ”Žืขื‘

The bottom line (TL;DR)

  • API = a service counter: method, URL, headers, body, status.
  • Webhook = the other system calls us โ€” immediate and without polling.
  • Webhook response returns a status and JSON; return early.
  • Secure it with an API key in a header and a filter.
  • We built a lead-intake API with 401/400/201.

The key points โ€” in depth

1. HTTP and REST

Methods, query, headers, body, status codes.

2. Custom webhook

A unique address, data structure, Get request headers, a queue.

3. Webhook response

Status, body and headers; early in the scenario.

4. Security

API key + filter, IP restrictions, HMAC.

5. The HTTP module

Auth, query, JSON body, Parse response, Evaluate all states as errors.

6. Create JSON

Valid JSON from fields โ€” especially with special characters.

7. Make an API call

Access to any endpoint with an existing connection.

Concept cards (click or press Enter to flip)

API
An interface through which systems ask each other for data and actions.
Webhook
An address that another system sends an event to.
Webhook response
A module that returns a response to the sender.
Status code
A number marking success or the type of failure.
Header
Metadata in a request: auth, content type.
Create JSON
Building valid JSON from fields.
Make an API call
A module that calls any endpoint with an existing connection.
429
Too many requests โ€” you need to slow down.

Spaced repetition โ€” the session concepts

Mark "I knew it" or "Not yet" โ€” the cards you did not know come back more often. Cards from all the sessions are in the arcade.

Quick cheat sheet

WhatDetails
GET / POST / PUT / PATCH / DELETERead / create / replace / update / delete
200 ยท 201 ยท 400 ยท 401 ยท 404 ยท 429 ยท 500The main status codes
Webhooks โ†’ Custom webhookA receiving address
Get request headersHeaders in the output
Webhooks โ†’ Webhook responseReturn a response
JSON โ†’ Create JSONA valid request/response body
Content-Type: application/json; charset=utf-8Correct encoding
get(map(1.__IMTHEADERS__; "value"; "name"; "x-api-key"); 1)Reading a header

Common mistakes to avoid

  • Putting Webhook response after a slow module (AI) โ€” the sender gets a timeout.
  • Writing JSON by hand with mapping โ€” it breaks because of quotes.
  • An API key inside the URL.
  • Forgetting Get request headers so authentication always fails.
  • Leaving a webhook with no security at all in production.

Self-review questions

  1. What's the difference between 401 and 403?
  2. Why return the response early?
  3. How do you add an API key to a request and how do you check it?
  4. When HTTP and when Make an API call?
  5. What happens to requests when the scenario is off?

Homework and preparing for the next session

  1. The API should return 3 correct responses.
  2. Preparing for session 5: make sure you have access to Google Sheets, Gmail, Drive and Calendar in the course account.