General API Information

The Dailymotion Cloud public API is really similar to JSON-RPC. Requests and responses are valid JSON.

The API endpoint is http://api.dmcloud.net/api.

The client secret is the API key, which can be found under account/profile.

Request

A simple request is a JSON object with three parameters:

  • call (required): this is the object you want to access and its method separated by a dot (eg: media.create)
  • args (optional): the named arguments of the method as an object. (eg: {‘title’ : ‘my holidays’, ‘author’ : ‘john doe’})
  • auth (required): the authentication token, that we’ll describe later on.

Here is an example request:

{
    "call": "media.get_asset",
    "args":
    {
        "asset_name": "source",
        "id": "4c922386dede830447000009"
    }
    "auth": "4c1a4d3edede832bfd000003:e982eda83a0af51dfaed9a6f026815f6",
}

Response

A successful response is a JSON object with two mutually exclusive parameters:

  • result: the result of the method call.
  • error: an error code and a message describing the error.

An example successful response:

{
    "result":
    {
        "username": "johndoe",
        "first_name": "John",
        "last_name": "Doe",
        "created": 1284642250,
        "is_active": true,
        "email": "johndoe@company.com",
        "last_login": null,
        "api_key": "bdb51bd129328e5b901f077e397405b54a703279",
        "id": "4c923232dede823070000067",
        "permissions": []
    }
}

An example error response:

{
    "error":
    {
        "code": 630,
        "message": "Invalid parameters for media.set_meta"
    }
}

Authentication

The authentication token serves an identification purpose, and also uniquely signs the request so it can’t be altered undetected. Given the following request, there are three steps to generate the authentication token:

{
    "call": "media.get_asset",
    "args":
    {
        "asset_name": "source",
        "id": "4c922386dede830447000009"
    }
}

1/ First, you have to normalize your request payload as shown below:

 argsasset_namesourceid4c922386dede830447000009callmedia.get_asset
(i.e. concatenate all the JSON key-names and values recursively, without any separator).

To do this, one would implement a recursive method. For instance, in Python code:

def normalize(input=None):
    output = ''
    if type(input) in (list, tuple):
        for element in input:
            if type(element) in (dict, list, tuple):
                element = normalize(element)
            output += str(element)
    elif type(input) is dict:
        keys = input.keys()
        keys.sort()
        for key in keys:
            element = input[key]
            if type(element) in (dict, list, tuple):
                element = normalize(element)
            output += '%s%s' % (key, element)
    else:
        output = str(input)
    return output

2/ You then need to concatenate your user_id, the above normalized block and your api_key together, and compute the MD5 checksum of the resulting data:

user_id  = '4c1a4d3edede832bfd000003'
api_key  = 'bdb51bd129328e5b901f077e397405b54a703279'
checksum = md5(user_id + normalize(request) + api_key)
# e982eda83a0af51dfaed9a6f026815f6

3/ You finally need to concatenate your user_id, the ‘:’ character and the above checksum to obtain the authentication token:

auth_token = user_id + ':' + checksum
# 4c1a4d3edede832bfd000003:e982eda83a0af51dfaed9a6f026815f6

HTTPS Authentication

The HTTPS API endpoint is https://api.dmcloud.net/api.

When using HTTPS, the authentication token is simplified, and here is its format:

<user_id>:<api_key>

So, using the following user id and API key:

user_id  = '4c1a4d3edede832bfd000003'
api_key  = 'bdb51bd129328e5b901f077e397405b54a703279'

then the auth token is:

4c1a4d3edede832bfd000003:bdb51bd129328e5b901f077e397405b54a703279

Here is an example request:

{
    "call": "media.get_asset",
    "args":
    {
        "asset_name": "source",
        "id": "4c922386dede830447000009"
    }
    "auth": "4c1a4d3edede832bfd000003:bdb51bd129328e5b901f077e397405b54a703279",
}

Curl echo test:

Here is a curl example allowing to test the authentication token:

curl -k -v -d '{"call": "test.echo", "args": {"msg": "hello"}, "auth": "4c1a4d3edede832bfd000003:bdb51bd129328e5b901f077e397405b54a703279"}' https://api.dmcloud.net/api

Table Of Contents