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.
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!
Then, setting up the webhooks is done in two steps:
webhook_url
field on your user
object.webhook_events
field on the user
object. You should pass the list of events as a comma separated string.// 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 authntified user with the chosen values
$api->post(
'/me',
array(
'webhook_url' => 'https://testwebhook.com',
'webhook_events' => 'video.created,video.deleted',
'fields' => array('id', 'screenname', 'webhook_url', 'webhook_events')
)
);
DM.api(
'/me',
'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('/me',
{
'webhook_url': 'https://testwebhook.com',
'webhook_events': 'video.created,video.deleted',
'fields': 'id,screenname,webhook_url,webhook_events'
})
At the time of writing, you can subscribe to the following events on your Dailymotion account:
video.created
: Sent when the video is created (before publication and encoding).video.deleted
: Sent when the video is deleted.video.published
: Sent when the video is published.video.format.processing
: Sent while our video encoders is processing a video format (H264-512x384...)video.format.ready
: Sent when a the encoding of a video format is done.video.format.error
: Sent when an error occurred in the encoding process of a specific format.video.format.deleted
: Sent when a video format is deleted.An up-to-date list of events is available in the api error message.
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.
#### Answer format {#answer-format}
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 eventtimestamp
: a Unix timestamp with milliseconds precision (x1000)data
: JSON object with additional parameters related to the eventBelow are some examples of classical payloads:
{
"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",
"plugin_info":null,
"video_frame_count":8178,
"audio_nbr_channel":2,
"video_fps_mode":"CFR",
"file_size":72790640,
"duration":272.928,
"video_duration":272.873,
"container":"MPEG-4",
"video_height":720,
"video_interlaced":false,
"progress":100,
"checksum_sha1":"thechecksumsha1",
"audio_format":"AAC LC",
"is_hfr":false,
"video_rotation":0,
"video_aspect":1.7777777777778,
"video_format":"AVC",
"audio_bitrate":128011,
"video_width":1280,
"bitrate":2133622,
"audio_duration":272.928,
"video_bitrate":2000000,
"audio_rate":44100,
"checksum_md5":"thechecksum",
"video_fps":29.97,
"extensions":[
"mp4",
"m4v",
"m4a",
"m4b",
"m4p",
"3gpp",
"3gp",
"3gpp2",
"3g2",
"k3g",
"jpm",
"jpx",
"mqv",
"ismv",
"isma",
"f4v"
]
}
}
{
"type":"video.published",
"timestamp":1459863879000,
"data":{
"owner_id":"xyz",
"video_id":"xid"
}
}
{
"type":"video.deleted",
"timestamp":1459864364000,
"data":{
"owner_id":"xyz",
"video_id":"xid"
}
}
We recommend using RequestBin to troubleshoot WebHooks.