Tutorials

Video webhook API with signature verification and a delivery log

How DCAST webhooks work: signed requests, a secret kept encrypted, test and simulated events, a paged delivery log and a sending address you can allow.

dcast Team
9 min read
Share:
server, technology, computer, computer technology, cable, server, server, server, server, server
On this page

A video webhook API lets your server hear about events in your video account without polling for them. DCAST webhooks send your server a signed request when something happens in your account, and a delivery log records what happened to each attempt. This article covers what to build on your side: how to check the signature, how to look after the signing secret, how to test before real traffic arrives, how to read the log when something fails, and how to make your receiver safe to call more than once.

Upload, stream and sell your videos. Start on the free plan — no card needed.

Get Started Free

What a DCAST webhook gives your server

Think of a webhook as a small contract between DCAST and one endpoint of yours. You register the endpoint, DCAST sends a signed request to it when an event happens, and you answer with an HTTP status. Everything useful about the arrangement follows from three facts: the request is signed, each attempt is recorded, and each webhook is a separate object that you can manage on its own.

You manage webhooks through the partner API, using your partner key. The operations cover listing your webhooks, creating one, reading one, updating one, deleting one, and listing the event types you can choose from. Creating, changing and deleting each need the matching webhook permission on the key, so if a request is refused, check what the key is allowed to do before you suspect the endpoint.

Keep the partner key on your server. It belongs in your backend configuration, never in a page your visitors load, because anyone holding it can act on your webhooks.

Verify the webhook signature on the raw body

Signature verification is the step that separates a real delivery from anyone who has guessed your endpoint address. Each webhook has its own signing secret, and your receiver checks each delivery with the plain secret you were given. DCAST itself signs from an encrypted copy, which does not change anything on your side: you verify with the secret you hold.

The most common mistake is verifying after parsing. If your framework turns the body into an object and you then serialise it again, whitespace and key order can change, and a perfectly genuine delivery fails the check. Read the raw body exactly as it arrived, run the verification on those bytes, and only then parse it. Configure your web framework so the raw body is available to the route that receives webhooks.

When verification fails, work through the causes in order. First, confirm you are using the secret of the webhook that received the request, because every webhook has its own. Second, confirm nothing in front of your code, such as a proxy or a body parser, has altered the body. Third, if you recently rotated the secret, confirm your receiver has the new value. Reject anything that fails with an error status, and never act on its content.

Store and rotate the signing secret

DCAST keeps each signing secret encrypted at rest rather than in plain text, and the webhook details you read back through the API never include the secret. That has a practical consequence: you cannot fetch the secret later by reading the webhook, so save it in your own secret store when you receive it, not in a source file or a chat message.

If you suspect the secret has leaked, or a developer who knew it has left, use the operation that rotates the secret of a webhook. The new secret is stored encrypted in the same way as the first, and the answer to the rotation carries it.

Treat rotation as a switch with no overlap. The previous secret becomes invalid straight away, so a delivery signed with the new secret fails verification in your receiver until it holds the new value. Have the new secret ready in your secret store and the receiver configuration open before you call the operation, update the receiver the moment the answer arrives, and expect that a few deliveries in between may fail your check.

After the switch, look at the delivery log described below. Entries recorded with your error status around the time of rotation point to the gap, and a test delivery sent once the receiver is updated confirms that the new secret verifies.

Send a test delivery before real events arrive

Before you depend on real events, fire a test delivery. It goes only to the webhook you name, never to your other webhooks, so you can try a new endpoint without disturbing a production one. The request is accepted first and sent in the background, so the answer arrives before your receiver has been called.

That answer carries the event id of the request your receiver gets, so you can match the two in your own logs. Search your receiver logs for that id; if it appears, the path from DCAST to your code works. The test event has its own event type for tests, which lets your code tell it apart from real traffic. Note that a webhook must be active to receive a test, so activate it first if the test is refused.

Simulate an event with your own sample data

A test only proves that delivery works. To check that your code reads a payload correctly, simulate an event instead. A simulated event returns the rendered request with your own sample data in its body, so you can feed that request into your parser and signature check without waiting for something to happen in your account.

Sample data must be an object. If you send a string or a list, the request is refused with an error that names the payload field, which is a quick signal that your test script is building the wrong shape. Fix the sample data rather than wrapping it in something to get past the check.

Read the delivery log when something fails

The delivery log is where you go when a customer says an event never arrived. Every attempt is written to the log before the request reaches your receiver, so an attempt that is cut short still appears there with its outcome marked as unknown. An unknown outcome does not mean nothing happened: your server may have received and processed the request even though the result was never recorded. Check your own records before you assume the work was skipped.

When your endpoint answers, the same log entry records its response status, whether the delivery succeeded or failed. So a failing receiver shows up as an entry with your error status, not as a gap. Compare the status you see with what your own server logged for the same event id, and you can tell quickly whether the fault lies in your routing, your verification or your handler.

The log comes in pages. To read further back, open the next page with the cursor from the previous one. A cursor that does not belong to this webhook is refused with a clear error code, so if you receive that refusal, you have probably mixed up cursors between two webhooks in a script. Always take the cursor from the page you just read for the same webhook.

Replay a webhook delivery after you fix the receiver

The partner API also has an operation to replay a single delivery of a webhook, identified by the webhook and the delivery. It is the natural follow-up to the log: find the failed entry, fix your receiver, then replay that delivery rather than waiting for a new event. Like a test, it needs the webhook to be active, so activate it first if the replay is refused.

Because a replay can reach code that has already handled the original, the safeguard in the last section matters here too. Check your own receiver logs afterwards to confirm the fix worked.

Allow the sending address in your firewall

If your receiver sits behind a firewall, you can allow the sending address that DCAST publishes for webhooks, because deliveries are bound to that address. The partner API has an operation that returns it. Read it from there when you configure the firewall instead of copying an address from an old note, and revisit it whenever deliveries suddenly stop arriving.

An address allow-list is a convenience, not a substitute for verification. Keep checking the signature even when the network rules already restrict who can reach the endpoint, since the two protect against different mistakes.

Make your receiver safe to call twice

Any system that delivers messages over a network has to cope with repeats, and yours should too. Make your receiver safe to call twice with the same event id, so a repeated delivery does not repeat the work. In practice, store the event id of each delivery you handle, and when the same id comes in again, answer success without doing the work a second time.

Answer quickly as well. Do the minimum inside the request, which is to verify the signature, record the event id and queue the job, then do slow work in the background. A receiver that finishes its work before it answers invites cut-off attempts, and those show up in the log as unknown outcomes that you then have to untangle.

A short checklist before you go live

Before you rely on a webhook, run through the same sequence each time. Confirm your receiver reads the raw body and verifies the signature before parsing. Send a test delivery and find its event id in your logs. Simulate an event with realistic sample data and feed the result through your parser. Open the delivery log and confirm the entry shows your response status. Last, confirm that handling the same event id twice does no harm. If every step passes, you have a receiver that can be trusted with real events, and a log that tells you what went wrong when it does not.

Free tools for this topic

API documentation for this topic

d

dcast Team

Professional video streaming experts helping creators succeed.

Start Your Video Business Today

Upload, stream and sell your videos. Start on the free plan — no card needed.

Get Started Free