Sub topic 11
Connecting services with integrations, APIs and webhooks
This chapter assumes you have a working data model and at least one workflow in your builder, as covered in the earlier chapters. You should also know what a web request is: a message sent to a URL that returns a response.
Three ways to connect a service
Your MVP rarely does everything itself. Email, payments, calendars and spreadsheets are usually other products that you connect to yours. There are three common ways to do it.
| Method | What it is | Typical use |
|---|---|---|
| Built-in integration | A connector the platform provides. You sign in and pick options. | Send an email, add a row to a sheet |
| API call | Your app sends a request to another service and reads the reply. | Look up data, create a record elsewhere |
| Webhook | The other service sends a request to your app when something happens. | Payment succeeded, form submitted |
Start with built-in integrations. Use an API call when no connector exists. Use a webhook when you need to react to events in another service, and you don't want to keep asking whether anything changed.
Pull versus push
An API call is a pull. Your app asks, and the service answers. A webhook is a push. The service calls a URL you provide, and your app reacts.
Handling secrets
Most APIs require a key that proves who you are. Keep these rules:
- Store keys in the platform's secrets or environment settings, never in a page, a prompt or a shared screenshot.
- Use test or sandbox keys until you launch.
- Give each key the fewest permissions it needs.
AI builders sometimes paste a key directly into generated code. Check for this when you review the output.
Trusting a webhook
A webhook URL is public. Anyone who finds it can send a fake event, such as "payment succeeded". Most services therefore sign each request with a shared secret. Your app recomputes the signature from the raw request body and compares the two. The function below does this for HMAC-SHA256.
import { createHmac, timingSafeEqual } from "node:crypto";
// Verifies an HMAC-SHA256 signature (hex) sent by a service with a shared secret.
export function isValidSignature(rawBody, signatureHex, secret) {
const expected = createHmac("sha256", secret).update(rawBody).digest();
const received = Buffer.from(signatureHex, "hex");
return received.length === expected.length && timingSafeEqual(received, expected);
}Use the raw body, not parsed and re-serialized JSON, because any change in whitespace breaks the signature. timingSafeEqual compares in constant time, so an attacker can't learn the signature from response timing.
Common errors
- Duplicate events. Services retry when they get no quick reply, so the same event can arrive twice. Store the event ID and skip repeats.
- Slow handlers. Reply with 200 quickly, then do the heavy work afterward. A slow reply triggers retries.
- Rate limits. APIs cap requests per minute. Handle a 429 response by waiting and retrying.
- Silent failures. Log failed calls so you can see them. A workflow that fails without a trace is hard to debug.
Exercise
A payment service sends your app a "payment succeeded" webhook twice, a few seconds apart. What two things should your handler do to avoid giving the customer double credit?
Show answer
First, verify the signature on each request. Second, store each event's ID and ignore any event whose ID you have already processed, so the repeat has no effect.