Hi,
I’m trying to add a new stream with PHP Curl and REST API, however I’m getting the api error 500.
Request:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_HTTPHEADER => array(‘Content-Type: application/json; charset=utf-8’, ‘Accept: application/json; charset=utf-8’),
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => ‘http://localhost:8087/v2/servers/defaultServer/vhosts/defaultVHost/applications/live/streamfiles’,
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_USERPWD => “user:password”,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS => [
‘name’ => ‘Stream01’,
‘serverName’ => ‘defaultServer’,
‘uri’ => ‘host/Stream01/live’
]
));
Response:
{
“message”: “The server encountered an unexpected condition which prevented it from fulfilling the request”,
“success”: false,
“wowzaServer”: “4.7.7”,
“code”: “500”
}
Any related message(s) in the logs on the server?
If you need help with finding the right API function and parameters, use the Swagger documentation (see https://www.wowza.com/docs/how-to-access-documentation-for-wowza-streaming-engine-rest-api).
For PHP, there’s also a library available on https://github.com/WowzaMediaSystems/wse-rest-library-php, so you don’t have to write your own implementation
Hi,
Here’s a function that I wrote to create stream files using PHP curl requests and the REST API. I’ve modified it to use your parameters and it’s working for me; the 3 main differences that I’ve noticed are:
- I’ve JSON encoded the data I’m sending for the stream
- I’ve included the Content-Length (of my json encoded data) in my http headers
- My http auth method is CURLAUTH_DIGEST while yours is CURLAUTH_ANY, although it should still work anyway
Hope this helps you out a bit
createStream("Stream01");
function createStream($name) {
$url = "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/streamfiles";
$target = array(
"serverName" => "_defaultServer_",
"name" => $name,
"uri" => "host/Stream01/live"
);
#var_dump($target["enabled"]);
$json = json_encode($target);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $json,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_USERPWD => "user:password",
CURLOPT_HTTPAUTH => CURLAUTH_DIGEST,
));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept:application/json; charset=utf-8',
'Content-type:application/json; charset=utf-8',
'Content-Length: '.strlen($json)));
curl_exec($ch);
curl_close($ch);