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.

Request

A simple request is 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 successfull response:

{
    "result":
    {
        "username": "johndoe",
        "first_name": "John",
        "last_name": "Doe",
        "created": 1284642250,
        "is_active": true,
        "email": "johndoe@company.com",
        "last_login": null,
        "api_key": "077c2e8cd1f17a860ab2952ddba0c045968afd21",
        "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 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

Table Of Contents

Previous topic

Welcome to the Dailymotion Cloud Developer website

Next topic

Creating streaming URL

This Page