Launch an ad break during a live event

📘

You are reading API v2 documentation

Still using the Legacy API? Access the Legacy API documentation.




Streaming live events is a plan feature

Please reach out to your Dailymotion Account Manager or our Support Team to subscribe and set up the feature on your account.

During a live event, ad breaks can be launched with up to 24 commercials per hour. When an ad break is triggered, all viewers will simultaneously receive mid-roll advertising in their Player, composed of one or several ads depending on the input number.


Prerequisites:

  • Livestream status: Your livestream must be on-air (status.onair: true)
  • Authentication: Request an access token with the live.manage scope.

Launch an ad break

Issue a POST request to https://api.dailymotion.com/v2/livestreams/{livestream_id}/advertising with the number of ads to display in the count field:

curl --request POST \
     --url https://api.dailymotion.com/v2/livestreams/<LIVESTREAM_ID>/advertising \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <ACCESS_TOKEN>' \
     --header 'content-type: application/json' \
     --data '{"count":1}'

Example response:

{
  "livestream_id": "x63456",
  "advertising": {
    "end_at": "2026-07-06T09:23:38Z",
    "remaining": 23
  }
}

The response returns:

  • advertising.remaining: How many ad breaks you can still trigger in the current hour.
  • advertising.end_at: Estimated end time of the current commercial break (ISO 8601).

Check advertising status

To monitor the current ad break status at any time, fetch the advertising object on your livestream:


curl --request GET \
     --url 'https://api.dailymotion.com/v2/livestreams/<LIVESTREAM_ID>?fields=advertising' \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <ACCESS_TOKEN>'
{
  "advertising": {
    "remaining": 3,
    "end_at": "2026-07-06T09:23:38Z"
  }
}

Run recurring ad breaks using Python

📘

Make sure you have Python 3.8 or later installed on your server.

Install the requests library:

pip install requests

Save the following script as adbreak.py, replacing the credentials and livestream ID with your own:

import requests

# Step 1 — Get an access token
auth_response = requests.post(
    'https://oauth2.dailymotion.com/v2/token',
    data={
        'grant_type': 'client_credentials',
        'client_id': '<YOUR_API_KEY>',
        'client_secret': '<YOUR_API_SECRET>',
        'scope': 'live.manage'
    }
)
auth_response.raise_for_status()
access_token = auth_response.json()['access_token']

# Step 2 — Launch an ad break
livestream_id = '<YOUR_LIVESTREAM_ID>'

ad_response = requests.post(
    f'https://api.dailymotion.com/v2/livestreams/{livestream_id}/advertising',
    headers={
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json'
    },
    json={'count': 1}
)
ad_response.raise_for_status()
print(ad_response.json())

To run this script automatically at a set interval (ie. every 15 minutes), schedule it using cron on your server:

crontab -e

Add the following line:

*/15 * * * * /usr/bin/python3 /path/to/adbreak.py
⚠️

Watch your hourly limit

You can launch a maximum of 24 ad breaks per hour. Check advertising.remaining in the response to track how many you have left.



👍

Not a Pro yet?

Subscribe to one of our Dailymotion Pro offers to monetize your content, create a channel and enjoy content management, distribution and analytics tools.



Did this page help you?