API Documentation: pushpublish.connect

Synopsis

Pushes a live stream or channel to another service. To push a stream the origin stream details (application, instance, and stream name), service type and destination stream name/key are required. Other parameters may be required based on the service you wish to connect. To connect to a service that has been stored using pushpublish.add the only parameter required is the 'push_service_id' param. The default source app and stream that was stored will be used unless a new app or stream is provided with this call. The PushPublish services we offer are Akamai HLS, Facebook, and any other RTMP based service.

Akamai HLS

Akamai HLS pushes require an Akamai Host and Stream ID

Facebook

Facebook pushes requires a destination host

Periscope

Requires destination host address and stream

Youtube

Youtube pushes require no additional fields

RTMP

RTMP Services will require a host address, and may also require a destination app, instance, port, username and password to connect.

Example Request (JSON)

Push Services Example Code (PHP)

	$request = array(
		'command' => 'pushpublish.connect',
		'api_key' => 'APX4GKLM0RKQLSP2FBO1ROPKSSW47DZE',
		'timestamp' => time(),
		'cdn' => 158,
		
		/* connect using stored details */
		'push_service_id' => 1234,
		'app' => 'demo-origin',
		'inst' => 'live',
		'stream' => 'stream_1',
		);
	    //Create request signature
    $json_request = json_encode($request);
    $sig = base64_encode(hash_hmac('sha256', $json_request,
        '8fc8c48da81e6a2a06a9556379bf798af508dc0792497c678b4c3532ba8b637f', true));
    $request['signature'] = $sig;
    $json_request = json_encode($request);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.scaleengine.net/stable/'); // Set the URL
    curl_setopt($ch, CURLOPT_POST, true); // Perform a POST
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If not set, curl prints output to the browser
    curl_setopt($ch, CURLOPT_HEADER, false); // If set, curl returns headers as part of the data stream
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => $json_request)); //'Json' string or 'PHP' serialized return
    
    //If your PHP host does not have a proper SSL certificate bundle, you will need to turn off SSL Certificate Verification
    //This is dangerous, and should only be done temporarily until a proper certificate bundle can be installed
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate.
    //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate.
    
    $response = curl_exec($ch); //Execute the API Call
    if (!$response) {
        die('Failed to connect to ScaleEngine API');
    }
    
    //Decode the response as an associative array 
    $arrResponse = json_decode($response, true); 
    if ($arrResponse) {
        //Operation completed successfully
        //TODO Add work here
        print_r($arrResponse);
    } else {
        //Operation failed
        echo 'An error occured processing your request:';
        print_r($response);
    }
    	

Akamai Example Code (PHP)

	$request = array(
		'command' => 'pushpublish.connect',
		'api_key' => 'APX4GKLM0RKQLSP2FBO1ROPKSSW47DZE',
		'timestamp' => time(),
		'cdn' => 158,
		
		'app' => 'demo-origin',
		'inst' => 'live',
		'stream' => 'stream_1',
		'service_name' => 'akamai',
		'dst_stream' => 'destination_stream_name',
		'server_tag' => 'SER1',
		'entry_name' => 'session_1', //optional
		'adaptive_group' => 'group1', //optional
		
		'origin_url' => 'jb-origin.secdn.net', // optional
		
		/* Akamai Params */
		'host_id' => 'akamai_host_id', 
		'stream_id' => 'akamai_stream_id', 
		'event_name' => 'my_event', 	//optional
		'push_source' => true,		//optional
		'redundant_playlist' => 1,	//optional
		
		/* Advanced Settings */
		'playlist_count' => 0,		//optional
		'playlist_timeout => 120000, //optional
		'playlist_across_sessions' => 0, //optional
		'relative_playlist' => 0, 	//optional
		'bitrate_order' => 'high2low', //optional
	);
	    //Create request signature
    $json_request = json_encode($request);
    $sig = base64_encode(hash_hmac('sha256', $json_request,
        '8fc8c48da81e6a2a06a9556379bf798af508dc0792497c678b4c3532ba8b637f', true));
    $request['signature'] = $sig;
    $json_request = json_encode($request);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.scaleengine.net/stable/'); // Set the URL
    curl_setopt($ch, CURLOPT_POST, true); // Perform a POST
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If not set, curl prints output to the browser
    curl_setopt($ch, CURLOPT_HEADER, false); // If set, curl returns headers as part of the data stream
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => $json_request)); //'Json' string or 'PHP' serialized return
    
    //If your PHP host does not have a proper SSL certificate bundle, you will need to turn off SSL Certificate Verification
    //This is dangerous, and should only be done temporarily until a proper certificate bundle can be installed
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate.
    //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate.
    
    $response = curl_exec($ch); //Execute the API Call
    if (!$response) {
        die('Failed to connect to ScaleEngine API');
    }
    
    //Decode the response as an associative array 
    $arrResponse = json_decode($response, true); 
    if ($arrResponse) {
        //Operation completed successfully
        //TODO Add work here
        print_r($arrResponse);
    } else {
        //Operation failed
        echo 'An error occured processing your request:';
        print_r($response);
    }
    	

RTMP Example Code (PHP)

	$request = array(
		'command' => 'pushpublish.connect',
		'api_key' => 'APX4GKLM0RKQLSP2FBO1ROPKSSW47DZE',
		'timestamp' => time(),
		'cdn' => 158,
		
		'app' => 'demo-origin',
		'inst' => 'live',
		'stream' => 'stream_1',
		'service_name' => 'rtmp',
		'dst_stream' => 'destination_stream_name',
		'entry_name' => 'session_1',
		
		'origin_url' => 'jb-origin.secdn.net', // optional
		
		/* RTMP Params */
		'dst_host' => 'rtmp.host.com', //do not include rtmp://
		'dst_port' => 1935,
		'dst_app' => 'destination_app',
		'dst_appinst' => 'destination_instance',
		'dst_user' => 'destination_username',
		'dst_pass => 'destination_password',
	);
	    //Create request signature
    $json_request = json_encode($request);
    $sig = base64_encode(hash_hmac('sha256', $json_request,
        '8fc8c48da81e6a2a06a9556379bf798af508dc0792497c678b4c3532ba8b637f', true));
    $request['signature'] = $sig;
    $json_request = json_encode($request);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.scaleengine.net/stable/'); // Set the URL
    curl_setopt($ch, CURLOPT_POST, true); // Perform a POST
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If not set, curl prints output to the browser
    curl_setopt($ch, CURLOPT_HEADER, false); // If set, curl returns headers as part of the data stream
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => $json_request)); //'Json' string or 'PHP' serialized return
    
    //If your PHP host does not have a proper SSL certificate bundle, you will need to turn off SSL Certificate Verification
    //This is dangerous, and should only be done temporarily until a proper certificate bundle can be installed
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate.
    //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate.
    
    $response = curl_exec($ch); //Execute the API Call
    if (!$response) {
        die('Failed to connect to ScaleEngine API');
    }
    
    //Decode the response as an associative array 
    $arrResponse = json_decode($response, true); 
    if ($arrResponse) {
        //Operation completed successfully
        //TODO Add work here
        print_r($arrResponse);
    } else {
        //Operation failed
        echo 'An error occured processing your request:';
        print_r($response);
    }
    	

Request Fields

command [REQUIRED] [string] - API command to execute
cdn_id [REQUIRED] [int] - The ScaleEngine CDN ID of your account
api_key [REQUIRED] [string] - The API key provided as part of your account
timestamp [REQUIRED] [int] - The unix timestamp of your request, used to prevent authenticated API requests from being replayed
push_service_id [OPTIONAL] [int] - ID of the stored PushPublish Service
app [REQUIRED] [string] - The ScaleEngine Application name
inst [REQUIRED] [String] - Name of the Application Instance
stream [REQUIRED] [string] - Stream name
service_name [REQUIRED] [string] - service type.
Available services:
  • akamai
  • rtmp
  • facebook
dst_stream [REQUIRED] [string] - PushPublish Destination Stream Name
entry_name [REQUIRED] [String] - Unique Key used to reference the PushPublish session. Required if connecting/disconnecting without a push service id
adaptive_group [OPTIONAL] [string] - Name for a group of transcoded streams
host_id [OPTIONAL] [string] - Service Host ID
stream_id [OPTIONAL] [int] - Service Stream ID
event_name [OPTIONAL] [String] - Akamai stream event name.
dst_host [OPTIONAL] [string] - Destination Host Address. Do not inlcude protocol or port in the address.
dst_port [OPTIONAL] [int] - Destination Port Number.
dst_app [OPTIONAL] [string] - Destination Application Name
dst_appinst [OPTIONAL] [string] - Destination Application Instance Name
dst_pass [OPTIONAL] [string] - Destination Password
dst_user [OPTIONAL] [string] - Destination Username
playlist_count [OPTIONAL] [int] - How many chunks to have on the manifest for each rendition. [Default: 0]
playlist_timeout [OPTIONAL] [string] - How many milliseconds to keep the playlist after the encoder disconnects. [Default: 120,000]
playlist_across_sessions [OPTIONAL] [int] - Set to 1, keep the playlist when the encoder disconnects, instead of starting over. [Default: 0]
relative_playlist [OPTIONAL] [int] - [Default: false]
bitrate_order [OPTIONAL] [string] - "high2low" shows the top bitrate first in the rendition list, or "low2high" shows the lowest bitrate first. [Default: high2low].
origin_url [REQUIRED] [string] - Defines the url address of an origin to be called. Defaults to jb-origin.secdn.net for origins and jb-chorigin.secdn.net for channels.
server_tag [REQUIRED] [string] - The Server Tag to use when connecting a Push Publish service. This is required when connecting a service which has the primary / backup servers locked.

Example Result (JSON)

	{
	"message": "cupertino-akamai connected",
	"status": "success",
	"handle_time":"0.3795 seconds"
	}
	

Result Fields

message [string] - Debugging message
status [string] - "success" or "failure"
handle_time [float] - The amount of time spent processing your request