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. If the
answer never reached you, rotate the secret to get one you can see.
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 sends a subscription a test delivery and shows what your
endpoint answered (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.
Add "payloadVersion": 2 to be sent the newer body, which has the same structure for
every event. Left out, the subscription has version 1, the older bodies (see
Payloads below). Webhook payload versions
describes version 2 and how to switch.
Event types
Each trigger links to its body in the API reference: the version 1 body, which a
subscription created without payloadVersion is sent. The version 2 bodies are listed under
Webhook events (payload version 2).
| 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_… (test_… on a test delivery). 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). |
webhook-test |
true on a test delivery, and absent on every real one. |
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.
A subscription that keeps failing is turned off
When every attempt to a subscription has failed for five days, with no delivery in
between, Pitchlane turns the subscription off. It is not deleted. No new event is sent
to it while it is off, and an event still waiting for a retry ends, unsent, when that
retry comes round. If you turn it back on before then, the event is still delivered. A
410 Gone is different: that deletes the subscription.
- The account’s owner gets an email naming the trigger, the URL’s host and, for a campaign’s subscription, the campaign.
GET /webhookslists it withdisabledAt, the time it was turned off. A subscription that is on has nodisabledAt.- Updating it turns it back on, with or without a new URL:
PUT /webhookswith itsid, or saving it in the dashboard. The five days count again from its next failure.
A single delivery that succeeds resets the count, so a receiver that is down for a day or two is never turned off.
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 webhook created in the app (Profile → All Webhooks, or a campaign’s webhooks): the app shows its secret once, when you save it.
- A subscription that has none (
signedisfalse: one made before signing):POST /webhooks/{webhookId}/secretgives it one and answers it once; in the app, Generate signing secret next to the webhook does the same. 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.
To get a new one, rotate it.
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.
Rotating a secret
Rotate a subscription’s secret when you never saw it (the answer that carried it was lost), when you lost it, or when it leaked. Rotating gives the subscription a new secret and answers it once, as creating one does; it works for a subscription that has no secret yet too, which then gets its first.
Set your API key and the subscription’s id first (id in GET /webhooks):
export PITCHLANE_API_KEY="your API key"
export WEBHOOK_ID="the subscription's id"
curl -X POST "https://api.pitchlane.com/api/public/v1/webhooks/${WEBHOOK_ID}/secret/rotate" \
-H "X-API-Key: ${PITCHLANE_API_KEY}"
In the app, Rotate signing secret next to a signed webhook does the same.
For 24 hours, both secrets work. Every delivery after the rotation is signed with the
new secret. While the old one is still active, until previousSecretExpiresAt (in the
answer, and in GET /webhooks), it is also signed with the old one: webhook-signature
carries two signatures, space separated, as the Standard Webhooks specification has it for
rotation:
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4= v1,3p6OSmOh0y5DkrSBSbjkx3lRrTGbqTfu5ADzaKDljXk=
A rotation with expireOldNow (below), or one that gives a subscription its first secret,
keeps no old secret: previousSecretExpiresAt is null and deliveries carry one
signature.
Step 5 of Checking a signature already accepts a request when any one entry matches, and so do the official libraries, so a receiver that still holds the old secret keeps verifying while you put the new one in place. You do not need to change your verifier. Switch to the new secret within the 24 hours; after that, requests are signed with the new secret alone. A retry of an earlier event is signed when it is sent, so it carries the new signature too.
To check your receiver during the switch, send it a test: a test carries the same signatures a real delivery would at that moment, both while the old secret is still active, so a receiver holding either one accepts it.
A leaked secret: stop signing with it now. Send {"expireOldNow": true} (with the
same two variables set):
curl -X POST "https://api.pitchlane.com/api/public/v1/webhooks/${WEBHOOK_ID}/secret/rotate" \
-H "X-API-Key: ${PITCHLANE_API_KEY}" -H "Content-Type: application/json" \
-d '{"expireOldNow": true}'
In the app, tick Stop the current secret now when you rotate. What this does and does not do:
- Attempts that start after the rotation are signed with the new secret only, and the old one is deleted on our side.
- An attempt already in flight when you rotate may still go out signed with the old secret: it was signed before the rotation took effect.
- Pitchlane cannot make your receiver stop trusting the old secret. Whoever holds the leaked secret can sign requests your receiver accepts until you remove it there. Put the new secret in place and remove the old one from your receiver; that is what ends the leak.
- Until your receiver has the new secret, it rejects our deliveries. Each rejected one is retried on the usual schedule, which ends about 27.5 hours after the event, so update your receiver promptly: a delivery whose retries run out before then is not sent again.
Rotating again drops the oldest secret: a delivery never carries more than two
signatures. A rotation repeated with the same Idempotency-Key is answered without the
secret; rotate again, without that key, to get one you can see.
Testing your verifier
Send test on a webhook in the app’s list, or POST /webhooks/{webhookId}/test with
the API, sends that subscription a test delivery: the example body of its trigger (as in
the API reference, with the time and id of now) to its URL, once. It is sent
exactly as a real delivery is, with the same headers, and signed with the
subscription’s secret when it has one (signed is true), so it is a good way to
test your verifier. While a rotation keeps the old secret active, a
test carries both signatures, as a real delivery does. The app shows the status your endpoint answered, or why it could not
be reached; the API answers the same in status, result and hint.
A test delivery is marked in two ways:
- its
webhook-id, which is also the body’seventId, starts withtest_. Every real event’s id starts withevt_, and never withtest_; - it has a
webhook-test: trueheader, which no real delivery has.
For a signed subscription, the id decides. The signature covers the id, the
timestamp and the body, but not the other headers. So verify the signature first, then
tell a test from an event by the verified id: test_… is a test, evt_… is an event.
webhook-test is a convenience, for logs and routing; do not classify a delivery by it
alone. If the two disagree (webhook-test: true with an evt_… id, or a test_… id
without the header), the request did not come from Pitchlane as sent: reject it as an
error rather than setting it aside or processing it.
For a subscription without a secret (signed is false), neither marker is
authenticated: anyone who knows the URL can send either. Give it a signing secret before
you rely on telling tests from events.
The body has no other difference: its fields are those of the trigger’s schema. Store
or discard a test as you like; do not act on its example video or campaign. A test is
not retried, does not appear among your events, and an answer of 410 does not remove
the subscription as it would for a real delivery. A test neither counts toward nor ends
the five days of failures that turn a subscription off, and a turned-off subscription can
still be tested: use it to check that your endpoint works again, then update the
subscription to turn it back on (a test does not).
A test follows a 307 or 308 redirect, which repeats the same signed POST. It does not
follow a 301, 302 or 303: those turn the POST into a GET without its body, so the
test reports the redirect’s status instead. Point the subscription at the URL your endpoint
redirects to. Tests are limited to 5 a minute per
subscription and 20 a minute per account, are sent only to URLs on the public
internet, and are not offered for subscriptions managed by Zapier.
Check that your receiver accepts a test of a signed subscription, then change one
character of the secret on your side and check that it rejects the next one. A test of
a subscription whose signed is false has no webhook-signature, so a receiver that
verifies must reject it: give the subscription a secret first.
Subscriptions without a secret
A subscription whose signed is false is delivered without webhook-signature.
Until you have given it a secret (generate or rotate, above), 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). Which structure the rest has depends on the subscription’s
payload version:
- Version 2 (
"payloadVersion": 2): one envelope for every event, with the API’s Video object asvideo, the lead’s contact fields aslead, and the Campaign object ascampaignon campaign events. Its bodies are in the API reference under Webhook events (payload version 2), one entry per trigger. The body itself says"payloadVersion": 2. - Version 1 (a subscription created without
payloadVersion, and Zapier’s): the body each event has always had. Its bodies are in the API reference under Webhook events, one entry per trigger; each trigger in the table above links to its entry. It stays supported, unchanged.
Both are signed the same way: the signature is over the body exactly as you receive it.
Three things to know before you read the version 1 bodies (none of them applies to version 2):
- 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. (In version 2 it is the stored video, under its realid.)- 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, or use version 2.
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.