Docs

Overview

Set up webhook notifications, verify their signatures, and test your integration.

A webhook is an HTTP request that notifies your server when an event occurs. Chunkify sends a JSON payload to your webhook URL for each event you subscribe to.

For example, the asset.playback_ready event tells your application when the HLS stream becomes playable.

The video asset may still be preparing, with its poster and timeline previews not yet available.

asset.ready means playback, the poster, and timeline previews are all ready. Subscribe to it as well if your application needs those additional URLs.

Set up a webhook in the dashboard

  1. In your Project, open Developers → Webhooks → Setup webhook.
  2. Enter your server's Webhook URL, choose an event group such as Assets, and select the events your application needs. Then select Create webhook.
  3. Copy the Webhook secret from the Webhooks page. Your server uses it to verify incoming notifications.

Webhook setup dialog with Asset events selected and delivery enabled

The webhook is enabled by default. Select asset.playback_ready to receive a notification as soon as the HLS stream is playable, or asset.ready when you also need the poster and timeline previews.

Set up a webhook with the SDK

Set events to the types your application needs. This example subscribes to asset.playback_ready so your server is notified when the HLS stream becomes playable.

import Chunkify from '@chunkify/chunkify';

const client = new Chunkify({
    projectAccessToken: 'My Project Access Token',
});

// Create a webhook
const webhook = await client.webhooks.create({
    url: 'https://example.com/webhook',
    events: ['asset.playback_ready'],
});

If you omit events, Chunkify subscribes the webhook to all supported events except asset.playback_ready. Subscribe to it explicitly to receive playback notifications.

Event history

Chunkify records every supported event, even when no webhook is configured.

For each subscribed webhook, Chunkify creates a notification and records its delivery attempts. Creating a webhook does not send past events.

Verify webhook signature

Chunkify signs notifications according to the Standard Webhooks specification.

Verify the signature before processing a notification. Use your Webhook secret, the raw request body, and the webhook-id, webhook-timestamp, and webhook-signature headers.

The raw request body is the JSON exactly as received, before your framework parses it. Parsing and re-encoding it can change the bytes and make signature verification fail.

These examples verify the signature and handle asset.playback_ready. Replace the example secret with your Project's Webhook secret.

// This example uses Express for simplicity
import express from 'express';
import type { RequestHandler } from 'express';
import Chunkify from '@chunkify/chunkify';


const app = express();
const PORT = 8787;

// Use raw body for signature verification
app.use(express.raw({ type: 'application/json' }));

const webhookHandler: RequestHandler = (req, res) => {
const headers: Record<string, string> = {
    'webhook-signature': req.header('webhook-signature') || '',
    'webhook-id': req.header('webhook-id') || '',
    'webhook-timestamp': req.header('webhook-timestamp') || '',
};

const client = new Chunkify({
    projectAccessToken: 'My Project Access Token',
    webhookKey: 'your secret key',
});

// Unwrap the webhook will also verify the signature using the secret key
let notification: Chunkify.UnwrapWebhookEvent;
try {
   notification = client.webhooks.unwrap(req.body.toString(), { headers });
} catch (error) {
    console.error('Error unwrapping webhook:', error);
    res.status(400).send('Error unwrapping webhook');
    return;
}

const event = notification.event;
console.log('Webhook event received:', event);
switch (event) {
    case 'asset.playback_ready':
        const payload = notification.data as Chunkify.UnwrapWebhookEvent.NotificationPayloadAsset;
        console.log(`Video asset ${payload.asset.id} can play`);
        break;
        // Complete with other cases for other event type as needed.
    default:
        console.log(`Unexpected event type: ${event}`);
}
res.status(200).send('OK');
};
    
app.post('/webhook', webhookHandler);
    
app.listen(PORT, () => {
console.log(`Test server listening on http://localhost:${PORT}`);
});

Return a 2xx response after accepting a notification. Chunkify retries failed deliveries, so make your handler safe to run more than once for the same event.

Testing your webhook integration locally

Use the Chunkify CLI to forward notifications to your local server. See Receive webhook notifications locally for the setup steps.

Manually send a notification

You can send a notification to a specific webhook to retry a failed delivery or test your handler. When a matching event is retained, Chunkify uses its saved payload.

Provide webhook_id, event, and the object_id of the resource that produced the event. For asset.playback_ready, use the video asset ID.

Notification attempts are limited to five for the same event and webhook. See Create a notification for the full request and response.

import Chunkify from '@chunkify/chunkify';

const client = new Chunkify({
    projectAccessToken: 'My Project Access Token',
});

const notification = await client.notifications.create({
    event: 'asset.playback_ready',
    object_id: 'ast_2G6MJiNz71bHQGNzGwKx5cJwPFS',
    webhook_id: 'wh_2G6MJiNz71bHQGNzGwKx5cJwPFS',
});