Content Management

Webhooks

Get real time notifications about your assets without using the API or logging into the CMS.

Webhooks allow you to receive real time notifications about the events that happen in TargetVideo video library.

Webhooks are designed in a way that will allow you to get real time information when video encoding process is finished, once the video is ready to be used/embedded, if the video is added/removed within a playlist and many more events. Using webhooks you will be able to perform custom actions based on the events that our system will provide.

❗ Important

Webhooks are available on premium plans only. If you are not on a premium plan, contact support@target-video.com to have them enabled.

Webhook setup

Once webhooks are enabled for your account, you can set them up in your website’s settings in TargetVideo.

Name

Description

Endpoint url

The URL each webhook is sent to, as an HTTP POST. Use HTTPS. Redirects are not followed, so give the final address.

Secret key

A string you choose. It is sent in every payload as secret — compare it with your copy before processing the request, and reject the request if it doesn’t match. It is a shared value, not a signature, so keep it private. If none is set, a default value is sent instead, so always set your own.

Timeout

How long we wait for your endpoint, in seconds. It covers connecting and the whole request. Default 3. Only TargetVideo support can change it — contact support@target-video.com.

Events

Use the event field to tell events apart. Older events also send a legacy method field, shown in the second column; method and data are deprecated, so don’t build on them.

Event

Legacy method

Fired when

video_add

add_video

A video is added to your website.

video_edit

edit_video

A video is edited.

video_delete

delete_video

A video is deleted.

video_kill_date

delete_video

A video reaches its kill date.

video_rejected

video_rejected

A video is marked as rejected.

sd_encoded

sd_encoded

The SD rendition has been created. Every video gets one.

video_encoded

video_encoded

Encoding has finished and all renditions are created.

error

—

Encoding failed — for example, the source file is invalid.

snapshot

—

A video’s snapshot images have been created or replaced.

record

—

A livestream recording has been saved as a video.

playlist_add

add_playlist

A playlist is created.

playlist_edit

edit_playlist

A playlist is edited.

playlist_add_videos

add_videos_to_playlist

Videos are added to a playlist.

add_videos_to_playlist

—

A video is added to a playlist automatically, because of its tags.

playlist_delete_videos

delete_video_from_playlist

Videos are removed from a playlist.

playlist_sort

sort_videos_in_playlist

The order of the videos in a playlist changes.

livestream_add_v2

—

A livestream channel is added to your website.

livestream_edit

—

A livestream channel is edited.

livestream_delete

—

A livestream channel is deleted.

livestreamschedule_add

—

A schedule is added to a livestream channel.

livestreamschedule_edit

—

A livestream schedule is edited.

livestreamschedule_delete

—

A livestream schedule is deleted.

Other parts of the platform send events too, named the same way — for example player_edit, unit_add or player_delete.

Request format

Each webhook is an HTTP POST with a multipart/form-data body. The body has a single field, data, holding the event as a JSON string. The body itself is not JSON — read the data field and decode it.

The decoded object contains event, scope (where in the platform the event was raised), response (the affected records, e.g. Video.id), api (true if the change was made through the API, false if in the CMS), timestamp (Unix time) and secret. The snapshot and tag-based add_videos_to_playlist events put the records at the top level instead of under response. This is the decoded data of an sd_encoded event:

{
   "response":{
      "Video":{
         "id":"734392"
      },
      "EncodingStatus":{
         "track_all":"1",
         "sd":"1",
         "ld":"0",
         "hsd":"0",
         "hd":"1",
         "fhd":"1",
         "streaming":"1",
         "snapshot":"1",
         "thumb":"1",
         "vtt":"1",
         "webp":"1",
         "ogg":"1",
         "mp3":"1"
      },
      "invoked_by":"MediaConvert"
   },
   "event":"sd_encoded",
   "scope":"Controller.Encodings",
   "method":"sd_encoded",
   "data":{
      "Video":{
         "id":"734392",
         "encoded":{
            "track_all":"1",
            "sd":"1",
            "ld":"0",
            "hsd":"0",
            "hd":"1",
            "fhd":"1",
            "streaming":"1",
            "snapshot":"1",
            "thumb":"1",
            "vtt":"1",
            "webp":"1",
            "ogg":"1",
            "mp3":"1"
         }
      },
      "invoked_by":"MediaConvert"
   },
   "api":false,
   "warning":"Properties \"data\" and \"method\" will be deprecated at 1.1.2021. Please use \"response\" and \"event\" properties instead.",
   "timestamp":1614908944,
   "secret":"your_secret_key"
}

Receiving a webhook

Respond with any 2xx status within the timeout, and do slow work after responding. A minimal receiver in PHP:

$payload = json_decode($_POST['data'] ?? '', true);

// Reject anything that doesn't carry your secret key
if (!is_array($payload) || !hash_equals('YOUR_SECRET_KEY', (string)($payload['secret'] ?? ''))) {
    http_response_code(403);
    exit;
}

switch ($payload['event']) {
    case 'video_encoded':
        $videoId = $payload['response']['Video']['id'];
        // the video is ready: queue your own processing here
        break;
    case 'error':
        $videoId = $payload['response']['Video']['id'];
        // encoding failed: alert someone
        break;
}

http_response_code(200);

Delivery and retries

A delivery fails if your endpoint can’t be reached, doesn’t answer within the timeout, or returns a 4xx or 5xx status. A failed webhook is retried up to four more times — about 1, 5, 15 and 60 minutes after the first failure — and then dropped. A retry can repeat an event your endpoint already handled (for example, if it answered too slowly), so make your handler safe to run twice for the same event.

Things to know when you build your receiver:

  • A retry is an exact copy. It sends the same data as the first attempt, with the same timestamp. To spot duplicates, compare event, timestamp and the record IDs in response.

  • Order isn’t guaranteed. A retried event can arrive after newer events for the same video. Before acting on an event, check the record’s current state through the API.

  • A 3xx reply counts as delivered. Redirects aren’t followed, so an endpoint that redirects (for example from http to https) loses the event without any retry.

  • Retries go to the old address. A retry uses the endpoint URL, secret key and timeout that were set when the delivery first failed. If you change the endpoint, retries already queued still go to the old URL.

If your endpoint is down for more than about an hour, the events from that time are not sent again. To catch up, use the API to fetch the changes.

Webhooks · TargetVideo Developer Docs