Table of content

Subscribe to events on my account using webhooks


You want to stay informed live when a specific event happens on your Dailymotion account? You can now use our webhook feature to get notified.

Webhooks let you register a url that we can POST to anytime a specific event happens on your account. When the event occurs, for example when a successful encoding is ready in your account, Dailymotion creates an event object. This object contains all the relevant information, including the type of event and the data associated with that event. Dailymotion then sends a HTTP POST request with the event object to the URL you specified.

Configuring your webhook

You can set up the webhooks using the API. You will perform authenticated calls, so you have to request authentication for the user you want to set up webhooks for. Do not forget to request the manage_videos scope!

Note for Organizations:

Webhooks can only be set up by Owners (Admins and Editors don’t have the permission)

Then, setting up the webhooks is done in two steps:

  1. Add the callback url that you want to be requested when the events trigger the webhook. This is done by giving a value to the webhook_url field on your user object.
  2. Select the events you want to subscribe to and add them to the webhook_events field on the user object. You should pass the list of events as a comma separated string.
PHP
Javascript
Python
// we here use the password grant type for authentication, but you can use whatever is best for your use-case
$api = new Dailymotion();
$api->setGrantType(
    Dailymotion::GRANT_TYPE_PASSWORD,
    $apiKey,
    $apiSecret,
    array('manage_videos'),
    array(
        'username' => $account,
        'password' => $password,
    )
);

// we perform the POST request on the authenticated user with the chosen values
$api->post(
    '/user/<CHANNEL_ID>',
    array(
        'webhook_url' => 'https://testwebhook.com',
        'webhook_events' => 'video.created,video.deleted',
        'fields' => array('id', 'screenname', 'webhook_url', 'webhook_events')
    )
);
DM.api(
    '/user/<CHANNEL_ID>',
    'post',
    {
        webhook_url: "https://testwebhook.com",
        webhook_events: "video.created,video.deleted",
        fields: "id,screenname,webhook_url,webhook_events"
    },
    function (response) {  
        console.log(JSON.stringify(response));
        // or do whatever you want
});
d = dailymotion.Dailymotion()
d.set_grant_type(
    'password',
    api_key=API_KEY,
    api_secret=API_SECRET,
    scope=['manage_videos'],
    info={'username': USERNAME, 'password': PASSWORD})
d.post('/user/<CHANNEL_ID>',
    {
        'webhook_url': 'https://testwebhook.com',
        'webhook_events': 'video.created,video.deleted',
        'fields': 'id,screenname,webhook_url,webhook_events'
    })

Which events can you subscribe to?

At the time of writing, you can subscribe to the following events on your Dailymotion account:

video.createdSent when the video is created (before publication and encoding)
video.deletedSent when the video is deleted
video.publishedSent when the video is published
video.format.processingSent while our video encoders is processing a video format (H264-512×384…)
video.format.readySent when a the encoding of a video format is done
video.format.errorSent when an error occurred in the encoding process of a specific format
video.format.deletedSent when a video format is deleted

An up-to-date list of events is available in the api error message.


Receiving a webhook

Configuring your server to receive a new webhook is no different from creating any page on your website. Remember that your server is the server receiving the request. Webhook data is sent as JSON in the request’s body.

The payload returned by webhooks is formatted using JSON.

All events have the following keys at the root of the JSON body:

  • type: the type of the event
  • timestamp: a Unix timestamp with milliseconds precision (x1000)
  • data: JSON object with additional parameters related to the event

Below are some examples of classical payloads:

video.created
video.format.processing
video.format.ready
video.published
video.deleted
{
   "type":"video.created",
   "timestamp":1459863728000,
   "data":{
      "owner_id":"xzy",
      "video_id":"xid"
   }
}
{
   "type":"video.format.processing",
   "timestamp":1459863865000,
   "data":{
      "owner_id":"xyz",
      "video_id":"xid",
      "preset_name":"mp4_h264_aac_hd",
      "status":"processing",
      "progress":52
   }
}
{
   "type":"video.format.ready",
   "timestamp":1459864182000,
   "data":{
      "owner_id":"xyz",
      "video_id":"xid",
      "preset_name":"mp4_h264_aac_hd",
      "status":"ready"
   }
}
{
   "type":"video.published",
   "timestamp":1459863879000,
   "data":{
      "owner_id":"xyz",
      "video_id":"xid"
   }
}
{
   "type":"video.deleted",
   "timestamp":1459864364000,
   "data":{
      "owner_id":"xyz",
      "video_id":"xid"
   }
}

Troubleshooting

We recommend using RequestBin to troubleshoot Webhooks.


Dailymotion Webhook IPs

If you have IP restrictions in place, make sure to authorize the following Dailymotion webhook IPs on your server:

  • 3.254.17.195
  • 63.33.129.201
  • 18.202.188.16