Wowza Community

Hot to create app type of LiveHTTPOrigin via REST API?

How can I create new Application type of LiveHTTPOrigin via REST API? Whatever I do type of “live” is created?

Is there any additional param that I need to send via POST to enable this and what is it?

Thanks,

Hi Milos,

The easiest way to do this is to initially create and configure your application through the Manager UI, and then query it through a GET request. The returned JSON response can then be used to populate the POST or PUT query to create or update a new one with the same configuration.

For a LiveHTTPOrigin, the important parameters that you would need to include are:

  "appType": "LiveHTTPOrigin",
  "streamConfig": {
    "httpRandomizeMediaName": true
  },

You will also need to add the HTTPStreamer properties under the endpoint
/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/adv

    {
      "enabled": true,
      "canRemove": true,
      "name": "httpOriginMode",
      "value": "on",
      "defaultValue": "",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "cupertinoCacheControlPlaylist",
      "value": "max-age=1",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "cupertinoCacheControlMediaChunk",
      "value": "max-age=3600",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "smoothCacheControlPlaylist",
      "value": "max-age=1",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "smoothCacheControlMediaChunk",
      "value": "max-age=3600",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "smoothCacheControlDataChunk",
      "value": "max-age=3600",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "smoothStreamingEncryptionRandomIV",
      "value": "false",
      "defaultValue": "false",
      "type": "Boolean",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "sanjoseCacheControlPlaylist",
      "value": "max-age=1",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "sanjoseCacheControlMediaChunk",
      "value": "max-age=3600",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "mpegdashCacheControlPlaylist",
      "value": "max-age=1",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },
    {
      "enabled": true,
      "canRemove": true,
      "name": "mpegdashCacheControlMediaChunk",
      "value": "max-age=3600",
      "defaultValue": "no-cache",
      "type": "String",
      "sectionName": "HTTPCacheOrigin",
      "section": "/Root/Application/HTTPStreamer",
      "documented": true
    },

Michelle

Hi Michelle,

Thanks for the quick response!

Cause of using an API is that I want to completely avoid using Manager UI. The goal is to use PHP API and completely automate creating wowza apps from my own Web app.

If I understand you well, there is no direct method for creating Live HTTP origin app, instead I need to create “other type of” app and update it accordingly?

How would that be implemented via your PHP SDK? Here I can find how to create an app (https://github.com/WowzaMediaSystems/wse-rest-library-php/blob/master/tests/application.php) but it is always forcing only “one” type of app using:

$streamConfig->setStreamType(“live”); //I’ve also tried other types but none is corresponding to Live HTTP origin type

Also, there is no example or any clue how I would “execute” above answer via your PHP SDK? Can you provide one, or point to proper API docs since current is very poor?

Hi Milos,

The JSON data above is used when sending the REST API command in an HTTP request, such as in curl. Since you are looking to use PHP, in your code where you construct the application, you will need to specify $appType as “LiveHTTPOrigin”. You would need to modify the StreamConfig class to include the httpRandomizeMediaName attribute so that you can set this as well for your application object. The advanced settings can all be added by creating an advancedSettings array list.

You should not need to change the $streamType as this should be live.

Michelle

Hi Michelle,

Could you please explain in more details how do I pass advanced settings data to create app method:

$wowzaApplication->create($streamConfig, $securityConfig, $modules,$dvrConfig,$transConfig,$drmConfig);

I’ve notices class.advancedSettings.php but it is almost empty and not used anywhere. Is there any PHP example where you are creating an App and sending custom paramateres via AdvancedSettings object?

Do I need to manually update your SDK as I did for StreamConfig class?

Also, I’ve notified that endopoint “/adv” is used in couple more files as an “inline” solution, avoiding usage of class.advancedSettings.php is that standard procedure?

Hi Michelle,

Any updates on class.advancedSettings.php and usage of “/adv” endpoint in PHP SDK?

Is there any explanation how do I configure encoding templates property via TranscoderConfig object in PHP SDK? I’ve managed to enable transcoding via TranscoderConfig, but templates are always empty whatever I configure for the $transConf->templates array property?

Here is a screenshot with a result:
https://www.dropbox.com/s/2s5oayy2lypa91n/Screenshot%202017-05-11%2009.12.14.png?dl=0

Also TranscoderConfig object is returning an error (as reported on github, I’ve fixed that modifying your class):

Can not deserialize instance of java.lang.Boolean out of START_ARRAY token\n at [Source: java.io.ByteArrayInputStream@74e63af9; line: 1, column: 2143] (through reference chain: com.wowza.wms.rest.vhosts.applications.ApplicationConfig[“transcoderConfig”]->com.wowza.wms.rest.vhosts.applications.transcoder.TranscoderAppConfig[“available”])

Thanks,

Hi Milos,

The REST API PHP library has been modified so that you can now set httpRandomizeMediaName as an attribute.

You will need to modify the application class so that you can incorporate requests to the /adv endpoint.

Add the following variables to your application class:

private $modules = array();
private $advancedSettings = array();

Add the following methods to your application class:

public function getAdv(){
$this->_skip["name"] = true;
$this->_skip["clientStreamReadAccess"] = true;
$this->_skip["appType"] = true;
$this->_skip["clientStreamWriteAccess"] = true;
$this->_skip["description"] = true;
$this->restURI = $this->restURI."/adv";
return $this->sendRequest($this->preparePropertiesForRequest(),array(), self::VERB_GET);
}
public function updateAdv(array $modules = null,
array $advancedSettings = null
){
$this->modules = $modules;
$this->advancedSettings = $advancedSettings;
$this->_skip["name"] = true;
$this->_skip["clientStreamReadAccess"] = true;
$this->_skip["appType"] = true;
$this->_skip["clientStreamWriteAccess"] = true;
$this->_skip["description"] = true;
$this->restURI = $this->restURI."/adv";
$response = $this->sendRequest($this->preparePropertiesForRequest($this),array(), self::VERB_PUT);
}

It would also be best to add a method to add AdvancedSettingItems to your AdvancedSettings class.

public function getAdvancedSettingItem($name, $value, $type, $section, $sectionName=null){
$ai = new AdvancedSettingItem();
$ai->name=$name;
$ai->value = $value;
$ai->type = $type;
$ai->section = $section;
$ai->sectionName = $sectionName;
return $ai;
}

When you create a LiveHTTPOrigin type of application, you will need to initially create the application, and then update it to add the advanced settings. Here’s an example that creates all of the advanced settings indicated above:

<?php
//
// This code and all components (c) Copyright 2006 - 2016, Wowza Media Systems, LLC. All rights reserved.
// This code is licensed pursuant to the Wowza Public License version 1.0, available at www.wowza.com/legal.
//
require_once("../include/config.php");
// example setting up a stream configuration element
$streamConfig =new com\wowza\entities\application\StreamConfig();
$streamConfig->setStreamType("live");
$streamConfig->setHttpRandomizeMediaName(true);
$streamConfig->setLiveStreamPacketizer(array("sanjosestreamingpacketizer","cupertinostreamingpacketizer"));
// example setting up a security configuration element
$securityConfig = new com\wowza\entities\application\SecurityConfig();
$securityConfig->secureTokenVersion = "0";
$securityConfig->clientStreamWriteAccess = "*";
$securityConfig->publishRequirePassword = "true";
$securityConfig->publishPasswordFile = "";
$securityConfig->publishRTMPSecureURL = "";
$securityConfig->publishIPBlackList = "";
$securityConfig->publishIPWhiteList = "";
$securityConfig->publishBlockDuplicateStreamNames = "false";
$securityConfig->publishValidEncoders = "";
$securityConfig->publishAuthenticationMethod = "digest";
$securityConfig->playMaximumConnections = "0";
$securityConfig->playRequireSecureConnection = "false";
$securityConfig->secureTokenSharedSecret = "";
$securityConfig->secureTokenUseTEAForRTMP = "false";
$securityConfig->secureTokenIncludeClientIPInHash = "false";
$securityConfig->secureTokenHashAlgorithm = "";
$securityConfig->secureTokenQueryParametersPrefix = "";
$securityConfig->secureTokenOriginSharedSecret = "";
$securityConfig->playIPBlackList = "";
$securityConfig->playIPWhiteList = "";
$securityConfig->playAuthenticationMethod = "none";
// example setting up module(s) configuration element
$modules = new com\wowza\entities\application\Modules();
$modules->moduleList[] = $modules->getModuleItem("ModuleCoreSecurity", "ModuleCoreSecurity", "com.wowza.wms.security.ModuleCoreSecurity");
// Create this application
$wowzaApplication = new com\wowza\Application("livetest", "LiveHTTPOrigin", "*", "*", "testPHP");
// var_dump($wowzaApplication->getAll());
// var_dump($wowzaApplication->get());
// $response = $wowzaApplication->create($streamConfig);
$wowzaApplication->create($streamConfig, $securityConfig, $modules, null, null, null);
//example setting up advanced settings element
$advSettings = new com\wowza\entities\application\AdvancedSettings();
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("httpOriginMode", "on", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("cupertinoCacheControlPlaylist", "max-age=1", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("cupertinoCacheControlMediaChunk", "max-age=3600", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("smoothCacheControlPlaylist", "max-age=1", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("smoothCacheControlMediaChunk", "max-age=3600", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("smoothCacheControlDataChunk", "max-age=3600", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("sanjoseCacheControlPlaylist", "max-age=1", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("sanjoseCacheControlMediaChunk", "max-age=3600", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("mpegdashCacheControlPlaylist", "max-age=1", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
$advSettings->advancedSettings[] = $advSettings->getAdvancedSettingItem("mpegdashCacheControlMediaChunk", "max-age=3600", "String", "/Root/Application/HTTPStreamer", "HTTPCacheOrigin");
// Update the advanced settings for the application
$response = $wowzaApplication->updateAdv($modules->moduleList, $advSettings->advancedSettings);
// Remove the application
// $response = $wowzaApplication->remove();
var_dump($response);
?>

I hope this helps.

Michelle

Hi Michelle,

Any updates on class.advancedSettings.php and usage of “/adv” endpoint in PHP SDK? Any code example?

I tried create application as specified in documentation(https://www.wowza.com/docs/application-management-query-examples#createCurl) but received this response below:
{
“code”:“404”,
“success”:false,
“wowzaServer”:“4.6.0”,
“message”:“The server has not found anything matching the request URI”
}

Authentication is enabled by default which may be causing you a problem when performing an API call.

You can enable or disable API authentication here:
https://www.wowza.com/docs/how-to-change-the-authentication-method-for-the-wowza-streaming-engine-rest-api#disable

Can you also provide us with your full CURL command?