Create Live Streams Channels

Creating Live Stream channels using the API

Want to create Live Stream channels from your website or your application using a script? No problem - our API makes it super simple to do that!

👍

Our PHP SDK and Node SDK make getting embed codes for your content very simple and provide wrapper functions to perform all of the necessary steps from start to finish, only requiring you to set your API key, and pass the ID of the video content to generate the embed code for. If you are using one of these platforms, it is highly recommended to download and integrate the SDK to facilitate integration of all our API services into your application.

Whether you’re making this an automatic script to create a channel, or you’re making this a function of your website (for instance to allow your end-users to create live stream channels on your account) you’re going to need to collect a few pieces of information:

  • Name of the channel
  • A short description
  • Where the ingest point should be located (i.e. the region that the person is broadcasting from) - one of north_america, asia_pacific or europe
  • The number of renditions (bitrates/resolutions) the end user wants to broadcast (multi-bitrate broadcast allowing their viewers the ability to use the best bitrate for their connection automatically through our player). You can set between 1 and 5 renditions.

NB: if you create a channel with multiple renditions, you will need to stream all renditions.

Once a channel is created with a certain number of renditions, if you want to increase reduce the number of renditions in use, you’re going to need to Delete Your Channel and create a new one.

If this is coming from the user, you’re going to want to go ahead and create a form on your site that they can fill in these details with, as well as a button to initiate the creation, otherwise, feed this in from your script using the logic that best suits your use case.

You may also wish to ask for information like a splashscreen image and thumbnail image, but this is not essential at this stage, and can be added later.

Once you have this information, if you are accessing our API directly, with your API key, you’re going to make a POST request to https://developer.dacast.com/v2/channel, for instance:

curl "https://developer.dacast.com/v2/channel" \
  -X POST \
  -d "{\n   \"title\":\"My First Channel\",\n   \"description\":\"I am a test\",\n   \"region\":\"europe\",\n   \"rendition_count\":3\n}" \
  -H "X-Api-Key: insertYourApiKeyHere" \
  -H "X-Format: default"
var myHeaders = new Headers();
myHeaders.append("X-Api-Key", "insertYourApiKeyHere");
myHeaders.append("X-Format", "default");

var raw = "{\"title\":\"My First Channel\", \"description\":\"I am a test\", \"region\":\"europe\",\"rendition_count\":3}";

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://developer.dacast.com/v2/channel", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://developer.dacast.com/v2/channel',
  'headers': {
    'X-Api-Key': 'insertYourApiKeyHere',
    'X-Format': 'default'
  },
  body: '{"title":"My First Channel", "description":"I am a test", "region":"europe","rendition_count":3}'

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
import requests

url = "https://developer.dacast.com/v2/channel"

payload = "{\"title\":\"My First Channel\", \"description\":\"I am a test\", \"region\":\"europe\",\"rendition_count\":3}"
headers = {
  'X-Api-Key': 'insertYourApiKeyHere',
  'X-Format': 'default'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://developer.dacast.com/v2/channel',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{"title":"My First Channel", "description":"I am a test", "region":"europe","rendition_count":3}',
  CURLOPT_HTTPHEADER => array(
    'X-Api-Key: insertYourApiKeyHere',
    'X-Format: default'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "{\"title\":\"My First Channel\", \"description\":\"I am a test\", \"region\":\"europe\",\"rendition_count\":3}");
Request request = new Request.Builder()
  .url("https://developer.dacast.com/v2/channel")
  .method("POST", body)
  .addHeader("X-Api-Key", "insertYourApiKeyHere")
  .addHeader("X-Format", "default")
  .build();
Response response = client.newCall(request).execute();

When the channel is successfully created, the response will contain various details essential for being able to stream to that channel.

The response body from the channel creation request looks like the below:

{
	"ads": null,
	"associated_packages": "",
	"category_id": 20,
	"company_url": "michael-elliott.co.uk",
	"config": {
		"live_transcoding": false,
		"login": "2469430730",
		"password": "f28fd0ce87b9844a",
		"publishing_point_backup": "rtmp://1628cb38-1fcc-42e8-8252-11f4147ba0a1.dacastmmd.bak.lldns.net/dacastmmd",
		"publishing_point_primary": "rtmp://1628cb38-1fcc-42e8-8252-11f4147ba0a1.dacastmmd.pri.lldns.net/dacastmmd",
		"publishing_point_type": null,
		"stream_name": "925459975c2c42d294024c71e9402e69_4500"
	},
	"countdown_date": null,
	"countdown_timezone": null,
	"counter_live_limit": -1,
	"countries_id": 0,
	"creation_date": "2021-11-16T15:09:58Z",
	"custom_data": null,
	"description": "I am a test",
	"enable_coupon": false,
	"enable_payperview": false,
	"enable_subscription": false,
	"external_video_page": "http://",
	"google_analytics": 1,
	"hds": "https://dacastmmd.mmdlive.lldns.net/dacastmmd/925459975c2c42d294024c71e9402e69/manifest.f4m?p=79\u0026h=e1a9d4fc0d2d89160b7b34da1792fbe8",
	"hls": "https://dacastmmd.mmdlive.lldns.net/dacastmmd/925459975c2c42d294024c71e9402e69/manifest.m3u8?p=79\u0026h=e1a9d4fc0d2d89160b7b34da1792fbe8",
	"id": "8ecc2482-49cf-9558-8072-de5044be6b18",
	"is_secure": 1,
	"live_recording_enabled": false,
	"noframe_security": 0,
	"online": true,
	"password": null,
	"pictures": {
		"splashscreen": [],
		"thumbnail": []
	},
	"player_height": 1080,
	"player_size_id": 10,
	"player_width": 1920,
	"publish_on_dacast": false,
	"referers_id": 0,
	"rtmp": null,
	"save_date": "2021-11-16T15:09:58Z",
	"schedule": null,
	"share_code": {
		"facebook": "https://iframe.dacast.com/live/4c857fbc-8fec-f113-9bb4-295e93f3f297/8ecc2482-49cf-9558-8072-de5044be6b18",
		"gplus": "https://iframe.dacast.com/live/4c857fbc-8fec-f113-9bb4-295e93f3f297/8ecc2482-49cf-9558-8072-de5044be6b18",
		"twitter": "https://iframe.dacast.com/live/4c857fbc-8fec-f113-9bb4-295e93f3f297/8ecc2482-49cf-9558-8072-de5044be6b18"
	},
	"splashscreen_id": 0,
	"stream_tech": "html5",
	"theme_id": "a3f39e14-5df2-52f8-e226-f5a858779455",
	"thumbnail_id": 0,
	"title": "My First Channel",
	"web_dvr": 0
}

You’re going to want to straight away grab the ID from the parameter “id” in the response, and store that somewhere so that you can look the channel up again in the future.

  • If you’re doing this on your website for your end users, creating a table that ties this ID to the user ID in your database is a good way of being able to look up what channels belong to what user.
  • Otherwise, if you are simply programmatically creating channels in your script to automate livestreaming for your own purposes, you can store the ID somewhere that suits your use case; or, you can simply Look Up Your List of Live Stream Channels in future to get any of these details if you don’t have anywhere to store this information.

Lines 6-14 in the above snippet contain your crucial information to enter into your encoder, or for your end users to plug into their encoders, to allow you to stream to this channel:

"config": {
		"live_transcoding": false,
		"login": "2469430730",
		"password": "f28fd0ce87b9844a",
		"publishing_point_backup": "rtmp://1628cb38-1fcc-42e8-8252-11f4147ba0a1.dacastmmd.bak.lldns.net/dacastmmd",
		"publishing_point_primary": "rtmp://1628cb38-1fcc-42e8-8252-11f4147ba0a1.dacastmmd.pri.lldns.net/dacastmmd",
		"publishing_point_type": null,
		"stream_name": "925459975c2c42d294024c71e9402e69_4500"
	},

The five key values are:

  • publishing_point_primary: the primary RTMP ingest server address
  • publishing_point_backup: the backup RTMP ingest server address, in case there is a problem with the primary at any point
  • login: the username
  • password: the password
  • stream_name: also known as stream_key

If it’s your end user that’s made the request, go ahead and grab these details from the response and display them to the end user on your website, otherwise if you’re using a script to create channels automatically, then send the details back to your encoder or wherever they need to be stored to be useful to you.

Depending on your, or your customer’s encoder, they will need to also enable authentication on their stream in order to use the login and password fields, so do advise your end users to go ahead and do that (in OBS, for example, there is a checkbox on the Streaming tab of settings called “Use authentication”).

Once you, or your end user, have plugged those details into your encoder, go ahead and hit “Start streaming”, and you should be able to see the stream in the player available at the URL in the share_code section.

Once everything is looking good: