Every value in these samples is a placeholder. Replace
sk_YOUR_API_KEY,
prj_YOUR_PROJECT_ID and whsec_YOUR_WEBHOOK_SECRET with your own values. Never
put a real key in code you share.
1. Upload a video (one part, up to 100 MiB)
Status: Available. The samples below upload a file that is under 100 MiB. It has one part. For larger files, see Direct upload, which splits the file into parts. The flow has three calls: create the upload, PUT the bytes to the part URL, and complete the upload. The part URL is pre-signed. Do not send your API key to it. If complete returns429 with the code encode_concurrency_limit, another of
your videos is still processing. Wait until it is ready, then try again. The
samples stop with an error on any failed call.
cURL
Node.js (18 or later)
Python (3.9 or later, standard library only)
PHP (8.1 or later, with the cURL extension)
2. Check the video status
A video starts asuploading, then processing, then ready or failed. Poll
the video until the status is ready or failed. Or subscribe to the
video.ready webhook and skip the polling.
Wait at least 5 seconds between checks. A video can take longer than a minute.
cURL
Node.js (18 or later)
Python (3.9 or later, standard library only)
PHP (8.1 or later, with the cURL extension)
3. Create a signed playback token
Create the token on your server, once for each time you show the video. Send the domain where the video plays. The token works only on that domain. The answer holdstoken, expiresAt and embedUrl.
The token is a playback credential. Send it to the browser only inside your page.
Do not put your API key in the browser.
cURL
Node.js (18 or later)
Python (3.9 or later, standard library only)
PHP (8.1 or later, with the cURL extension)
4. Verify a webhook signature
Each delivery carries aSegmnt-Signature header:
v1 value is the HMAC-SHA256 of <t>.<raw body>. The key is your signing secret,
used exactly as you got it, with the whsec_ prefix. Check the signature against
the raw request body, before you parse the JSON. Reject a timestamp more than
300 seconds from the current time.
The cURL sample below builds a signed sample delivery. Use it to check your own
receiver. It does not call our servers.
cURL
Node.js (18 or later)
express.raw({ type: "application/json" })
on this route, and read req.headers["segmnt-signature"].
Python (3.9 or later, standard library only)
request.get_data() (Flask) or request.body (Django) as raw_body. Do not pass the parsed JSON.
PHP (8.1 or later)
Next steps
- Direct upload: files over 100 MiB, with several parts.
- Create playback tokens on your server: when and how often to mint a token.
- Webhooks: the event list, retries and the delivery log.
- Errors: what each status code means.