Guide
Webhooks
Get an HTTP POST when a video is created, rendered or watched, or when a campaign is ready. Every event, its payload and how it is delivered.
A webhook subscription asks Pitchlane to POST a JSON body to your URL whenever one
kind of event happens. Each subscription is for one event type, its trigger.
Subscribe several times to hear about several.
Subscribe
Create a subscription with the API, sending your URL and the trigger:
curl https://api.pitchlane.com/api/public/v1/webhooks \
-H "X-API-Key: $PITCHLANE_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "webhookUrl": "https://example.com/hooks/pitchlane", "trigger": "VIDEO_RENDERED" }'
POST /webhookssubscribes to the event in every campaign of your account.POST /campaigns/{campaignId}/webhookssubscribes to it in one campaign.
Both answer with the subscription’s id, which DELETE /webhooks/{webhookId} removes.
The answer also carries the subscription’s signing secret, once. It starts with
whsec_, and it is in this answer only: no other endpoint returns it, and the same
request repeated with an Idempotency-Key is answered without it. Store it with the
subscription’s id; you need both to verify a webhook.
A subscription is answered with signed as well, on create, in GET /webhooks and on
update: true when it has a signing secret, so that its deliveries are signed.
The Webhooks section of the API reference has every subscription endpoint.
Your account’s subscriptions are also listed in the app under Profile → All
Webhooks, where Send Test Webhook posts an example body to the URL once. That
example is not signed (see Testing your verifier).
An event goes to the subscriptions that exist when it happens. A subscription made later is not sent events from before it, and nothing is sent for a campaign that has been deleted.
Event types
| Trigger | When it is sent |
|---|---|
VIDEO_CREATED |
A video was added to a campaign: created with the API, imported, or added in the app. |
VIDEO_UPDATED |
POST /campaigns/{campaignId}/videos with "upsert": true matched an existing video and changed it. |
VIDEO_RENDERED |
A video finished rendering and can be watched. |
VIDEO_UNRENDERABLE |
A video cannot be rendered: its lead or website is invalid, unsupported, or could not be recorded. |
CAMPAIGN_READY |
A campaign that was created or changed has been processed, and videos can be made from it. |
CAMPAIGN_FAILED |
A campaign’s setup or processing failed. Its problems say why. |
VIDEO_VIEWED |
Someone opened the video’s page. Sent for every view. |
VIDEO_FIRST_VIEWED |
The video’s page was opened for the first time. |
VIDEO_STARTED |
Someone started playing the video. Sent every time. |
VIDEO_FIRST_STARTED |
The video was played for the first time. |
VIDEO_FINISHED |
Someone watched the video to the end. Sent every time. |
VIDEO_FIRST_FINISHED |
The video was watched to the end for the first time. |
Sent once per video
VIDEO_CREATED, VIDEO_RENDERED, VIDEO_UNRENDERABLE and the three FIRST events are
sent at most once for a video until it is queued to render again. A video that is
re-rendered sends VIDEO_RENDERED again, and its next view sends VIDEO_FIRST_VIEWED
again. VIDEO_UPDATED is sent on every update.
VIDEO_UNRENDERABLE is sent only for problems with the lead or its website, errors of
type UNRECORDABLE, INVALID_LEAD, UNSUPPORTED or VALIDATION_ERROR reported by the
renderer. Internal errors do not send it, so our team can fix and retry those videos.
What counts as a view
The viewing events (VIDEO_VIEWED, VIDEO_STARTED, VIDEO_FINISHED and their FIRST
versions) are reported by the video’s page.
- A video link opened with
?dnt=1at the end records nothing and sends no webhooks. Use it to preview your own videos. - Email security scanners open every link in an email. Views from sessions that look
like such a scanner do not send
VIDEO_VIEWEDorVIDEO_FIRST_VIEWED. If the same session then interacts with the page, it was a person after all, and the held-back view events are sent then.
Campaign events
After a campaign is created, duplicated, or changed in a way that has to be processed
(its pitch video, pages, page images or videos, or outro), Pitchlane watches it until its
status is no longer processing. It then sends CAMPAIGN_READY (status ready) or
CAMPAIGN_FAILED (status failed). Several changes made while it is processing give one
event, for the state the campaign settles in. Drafts and archived campaigns send neither,
and a campaign that is still processing when the watch ends sends nothing.
Delivery
Every event, viewing events included, is delivered the same way, with retries spread over a day.
Each event is a POST with Content-Type: application/json and these headers:
| Header | Value |
|---|---|
webhook-id |
The event’s id, evt_…. The same as the body’s eventId, and the same on every attempt. |
webhook-timestamp |
When this attempt was made, in seconds since 1970 (Unix time). |
webhook-subscription-id |
The id of the subscription this delivery is for. |
webhook-signature |
The signature of this attempt, v1,…. Sent when the subscription has a signing secret (signed is true). |
If several of your subscriptions point at one URL, webhook-subscription-id tells you
which of them a request belongs to. Do not require it: a few old campaign subscriptions
have no id and are delivered without it.
Answer with any 2xx status within 15 seconds. Anything else is a failed attempt:
another status, a timeout or a connection error.
A failed attempt is retried on this schedule, each delay counted from the attempt before:
| Attempt | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Delay | at once | 5 s | 5 min | 30 min | 2 h | 5 h | 10 h | 10 h |
That is eight attempts over about 27.5 hours, after which the event is given up for that
URL. If a failed answer carries a Retry-After header (seconds, or an HTTP date), the
next attempt waits at least that long, but never more than an hour past the schedule.
- Answering
410 Gonedeletes the subscription. Zapier does this when a Zap is turned off. Nothing more is sent to it. - Each subscription is delivered on its own: a failing URL does not hold up the others, and they are not sent the event again.
- Each attempt reads the subscription again. If it was deleted, nothing more is sent. If its URL was changed, the next attempt goes to the new URL.
- Every attempt sends the same body and the same
webhook-id, with a newwebhook-timestampand so a newwebhook-signature. UseeventIdto skip an event you have already handled: if your server processed an attempt but its answer did not reach us, the next attempt brings the same event again. - Events are delivered independently of each other, so they can arrive out of order.
Order them by
eventAt.
Viewing events
The video’s page reports a view, a start or a finish as it happens, and Pitchlane delivers
it as above, with its eventAt the moment the page reported it. Should that report reach
us late (our side briefly unavailable), the event is delivered a minute or so later, with
the same eventAt.
Verifying a webhook
Pitchlane signs the deliveries of a subscription that has a signing secret, following the Standard Webhooks specification. Checking the signature tells you that a request came from Pitchlane and that its body was not changed on the way.
Getting the secret
- A new subscription:
POST /webhooksandPOST /campaigns/{campaignId}/webhooksanswer it once, assecret. - A subscription that has none (
signedisfalse: one made before signing, or made in the app):POST /webhooks/{webhookId}/secretgives it one and answers it once. From then on its deliveries are signed, so have your receiver ready first.
curl -X POST https://api.pitchlane.com/api/public/v1/webhooks/$WEBHOOK_ID/secret \
-H "X-API-Key: $PITCHLANE_API_KEY"
A subscription that already has a secret answers 409: a secret cannot be read again or
replaced. If you lose it, create a new subscription and delete the old one.
Each subscription has its own secret. Keep it like a password, and keep it with the
subscription’s id.
Checking a signature
- Find the secret.
webhook-subscription-idnames the subscription the request is for. Look up the secret you stored for it, and reject the request if you have none. The header is only a hint for this lookup; it is not signed, so trust nothing until the signature has matched. - Take the body exactly as it arrived, before parsing it as JSON. A body that was parsed and written out again will not verify.
- Build the signed content:
{webhook-id}.{webhook-timestamp}.{body}, the two header values and the raw body joined with full stops. - Compute its HMAC-SHA256, keyed with the base64-decoded part of the secret after
whsec_, and base64-encode the result. - Compare it with the part after
v1,of each space-separated entry inwebhook-signature, using a constant-time comparison. Accept the request when one matches. - Check the timestamp. Reject a request whose
webhook-timestampis more than five minutes from your clock, so that a captured request cannot be sent to you again later.
The official Standard Webhooks libraries do steps 2 to 6. In JavaScript:
import express from "express"
import { Webhook } from "standardwebhooks"
const app = express()
// The raw body: the signature is over the bytes that were sent.
app.post("/hooks/pitchlane", express.raw({ type: "application/json" }), async (req, res) => {
// 1. Verify. Your own storage: the secret you saved for this subscription id.
const secret = secrets.get(req.header("webhook-subscription-id"))
if (!secret) return res.sendStatus(401)
let event
try {
// Checks the signature and the timestamp, and returns the parsed body.
event = new Webhook(secret).verify(req.body.toString("utf8"), {
"webhook-id": req.header("webhook-id"),
"webhook-timestamp": req.header("webhook-timestamp"),
"webhook-signature": req.header("webhook-signature"),
})
} catch {
return res.sendStatus(401)
}
// 2 and 3. Deduplicate and accept durably, in one step: store the event under
// its id in your own database or queue. `webhook-id` is the same on every
// attempt, so an insert with a unique key on it does both.
try {
await inbox.insertOnce(req.header("webhook-id"), event)
} catch {
// Not stored: say so, and the event is sent again later.
return res.sendStatus(503)
}
// 4. Only now acknowledge. A retry of an event you already hold ends here too.
res.sendStatus(204)
})
// 5. Do the work from what you stored, outside the request.
secrets and inbox stand for your own storage. inbox.insertOnce writes the event
unless one with that id is already there, and succeeds either way.
Acknowledge only what you have stored. Once your server answers 2xx, Pitchlane
does not send that event again. If it answers before the event is safely stored and then
crashes, the event is gone. If it stores first and crashes before answering, the event
arrives again and the id you stored tells you so. Storing takes milliseconds; the slow
work (calling your CRM, sending an email) belongs after the answer, in a worker that
reads what was stored.
A retry of an event has the same webhook-id and body and a new webhook-timestamp,
so its webhook-signature is new as well. Verify every attempt on its own; the id is
what tells you that you have seen it.
Testing your verifier
Send Test Webhook in the app (POST /api/test-webhook) posts an example body to a
URL once. It is not sent for a subscription, so it carries no webhook-subscription-id
and no webhook-signature, whatever your subscriptions have. A receiver that
verifies must reject it, and that is the right outcome: do not loosen the verifier to
let it through.
To test verification, use a real event. Create a subscription with the API (its answer
has the secret), then cause the event, for example by creating a video in a test
campaign for VIDEO_CREATED, and check that your receiver accepts it. Change one
character of the secret and check that it rejects the next one.
Subscriptions without a secret
A subscription whose signed is false is delivered without webhook-signature.
Until you have given it a secret, the only check available is a long random token in the
URL you subscribe, for example https://example.com/hooks/pitchlane?token=….
When an action matters (sending an email, updating a CRM), treat the webhook as a
notification and read the current state from the API, for example
GET /videos/{videoId}, before you act on it.
Payloads
Every body is a JSON object with the trigger in event and the time it happened in
eventAt (ISO 8601, UTC). The fields of each body, with an example, are in the API
reference under Webhook events: one entry per trigger.
Each trigger in the table above links to its entry.
Three things to know before you read them:
- Video and campaign events carry the API’s objects.
videois the Video object thatGET /videos/{videoId}returns, andcampaignthe Campaign object thatGET /campaigns/{campaignId}returns.rawVideois the video as Pitchlane stores it; its fields are internal and can change, so usevideo. VIDEO_UPDATEDdescribes the row you sent, not the stored video. Itsvideo.id,shortIdandcreatedAtwere made for that row and are not the stored video’s. Match it to your lead withoriginalUid(or your campaign’s duplicate field), or list the campaign’s videos withGET /campaigns/{campaignId}/videos.- Viewing events carry the stored video, not the API’s Video object. Its id is
_id, and it has novideoUrlor thumbnail URLs. For the Video object, callGET /videos/{videoId}withvideo._id.
Checklist for your receiver
- Verify the signature, with the secret of the subscription named by
webhook-subscription-id. - Store the event under its
webhook-id(the body’seventId), skipping one you already hold. - Only then answer
2xx, within 15 seconds, and do slow work afterwards from what you stored. - Answer
410 Gonefrom a URL you have retired, so Pitchlane stops sending to it.