Basics to perform an API call
Introduction
A typical API call to the Dailymotion Platform API could look something like this, depending on if you’re using a public API key or a private API key:
GET https://api.dailymotion.com/videos?fields=id,title,language&channel=news&limit=100
GET https://partner.api.dailymotion.com/rest/videos?fields=id,title,language&channel=news&limit=100
In the above example, we are retrieving the following information from the Dailymotion Platform API: a list detailing the ID, title and language of the 100 most recent videos from the category news published on Dailymotion.com.
If this doesn’t look familiar for now, this guide will introduce you to the basic elements you need to know to easily interact with the Dailymotion API.
Endpoints
The Platform API is served over HTTPS and accessible on the following endpoints depending on your API key type:
https://api.dailymotion.com
https://partner.api.dailymotion.com/rest
Learn more about API keys.
Encoding
We recommend using UTF-8 encoding for all interactions with the API.
Request types
You can interact with the Dailymotion API using the following HTTP request types:
GET
GET
requests are used to retrieve resources.
Example: Retrieve public information about the video x3rdtfy
https://api.dailymotion.com/video/x3rdtfy
https://partner.api.dailymotion.com/rest/video/x3rdtfy
POST
POST
requests are used to create new resources or edit existing ones.
Example: To edit the title of a video
curl -X POST \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-F 'title=My New Title' \
"https://api.dailymotion.com/video/<VIDEO_ID>"
curl -X POST \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-F 'title=My New Title' \
"https://partner.api.dailymotion.com/rest/video/<VIDEO_ID>"
DELETE
DELETE
requests are used to delete resources.
Example: Delete a video
curl -X DELETE \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
"https://api.dailymotion.com/video/<VIDEO_ID>"
curl -X DELETE \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
"https://partner.api.dailymotion.com/rest/video/<VIDEO_ID>"
Objects & Connections
Objects
The Dailymotion API works with objects and IDs.
Here is a list of the various graph objects available through the Platform API. Some of them will only be available for reading, and some others for creation and edition too. Each object within has a unique identifier automatically assigned at creation.
Object name | Short description |
---|---|
channel | A channel object represents a category of videos on Dailymotion (formerly a channel), for example:sport , videogames , news Full list of available categories |
player | A player object holds several configuration properties (Picture-in-Picture settings, aspect ratio…)and is meant to be embedded with a script tag. |
playlist | A playlist object represents an ordered list of videos created by a user. Videos in a playlist do not necessarily have anything in common. |
subtitles | A subtitle object represents a file resource containing closed captioning for a given video. |
user | A user object represents a Dailymotion user account. Users are at the foundation of every other graph objects, sincemost of them are created through — or owned by — users. Users also represent the main authentication vector to Dailymotion services. |
video | The video object is the foundation of Dailymotion’ service. Videos are metadata containers wrapped around mediastreams and can be accessed either directly or through several connections through the Platform API. |
You can access the information of an object using this URL structure:https://api.dailymotion.com/<OBJECT_CLASS>/<OBJECT_ID>
Example: Retrieve information about the video that has the unique ID x3rdtfy
GET https://api.dailymotion.com/video/x3rdtfy
GET https://partner.api.dailymotion.com/rest/video/x3rdtfy
Connections
All of these objects are connected to each other via relationships: users own playlists, playlists own videos, videos own subtitles, etc. In a Graph API, these relationships are called connections.
You can explore the connections between objects using the URL structure https://api.dailymotion.com/<OBJECT_CLASS>/<OBJECT_ID>/<CONNECTED_OBJECT>
Example: Retrieve the list of videos of the user identified with the ID x1fz4ii
GET https://api.dailymotion.com/user/x1fz4ii/videos
GET https://partner.api.dailymotion.com/rest/user/x1fz4ii/videos
The Platform API reference lists the supported objects and connections.
Fields
API objects are composed of fields that contain different pieces of information.
Some fields are publicly readable, some others are not and require specific scopes granted during authentication. The privacy and required scopes for each field is specified in the Platform API Reference.
By default, only a few fields are returned. To request specific ones, you can use the fields
parameter and list the fields you need to be returned.
Let’s see different examples of fields request:
Fields by default
In the example below, we are calling the video object with the ID x3rdtfy, but no specific fields have been requested:
GET https://api.dailymotion.com/video/x3rdtfy
GET https://partner.api.dailymotion.com/rest/video/x3rdtfy
The JSON response to this call will return the default fields for a video object:
{
"id": "x3rdtfy",
"title": "Midnight Sun | Iceland",
"channel": "travel",
"owner": "x1aktrv"
}
id
of the videotitle
of the videochannel
: category of the videoowner
: user ID of the uploader
Specific fields
In this below example, we are calling the same video object than above, but we are specifying the fields we want to be returned (see exhaustive list of fields available for a video object). To do so, we are using the fields
parameter followed by each specific field we want, separated by a comma:
GET https://api.dailymotion.com/video/x3rdtfy?fields=id,url,published
GET https://partner.api.dailymotion.com/rest/video/x3rdtfy?fields=id,url,published
This call will return the following JSON response:
{
"id": "x3rdtfy",
"url": "https://www.dailymotion.com/video/x3rdtfy",
"published": true
}
Connected fields
Since some objets can be connected together, fields from these connected objects can also be assembled.
For instance, the owner
field of a video object returns the id
of a user object. Because these two objects can be connected, you can use any field of the user object (exhaustive list here) and assemble it with the video field of your choice, separated by a dot.
For instance, to retrieve the screenname
and url
of the owner of the video x3rdtfy, you can perform this request:
GET https://api.dailymotion.com/video/x3rdtfy?fields=id,title,owner,owner.screenname,owner.url
GET https://partner.api.dailymotion.com/rest/video/x3rdtfy?fields=id,title,owner,owner.screenname,owner.url
The response will look like this:
{
"id": "x3rdtfy",
"title": "Midnight Sun | Iceland",
"owner": "x1aktrv",
"owner.screenname": "Zeno",
"owner.url": "https://www.dailymotion.com/zeno"
}
owner.screenname
: name of the user who uploaded the videoowner.url
: URL of the user who uploaded the video
Filters
Some fields can also be used as filters to narrow down a list of objects.
All filters are listed in the API Reference, in the filters section of each object (i.e. Video filters).
To use filters, perform a GET
request and put your filters as parameters of the query string.
Example: The following request will list all English-speaking videos published in the category ‘technology’
GET https://api.dailymotion.com/videos?channel=tech&language=en
GET https://partner.api.dailymotion.com/rest/videos?channel=tech&language=en
Caching
The Platform API uses HTTPS Cache Control Mechanisms so you can benefit from security and speed improvements when performing API calls.
We recommend following the below guidelines to benefit from caching:
- If you’re using fields and/or filters in your query, sort them in alphabetic order. This will ensure the same URLs is used for each specific request.
- Send the access token in the Authorization HTTP header in order to keep this sensitive information out of the URL, like so:
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \
"https://api.dailymotion.com/file/upload"
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" \
"https://partner.api.dailymotion.com/rest/file/upload"
- If your application can potentially share the cache between different users, make sure you only share responses marked as “public” in the
Cache-Control
HTTP header. If your HTTP library respects theVary
HTTP header, it should automatically manage how to share and handle cached responses.