# Error 500 when trying to add new stream in REST API

**URL:** https://community.wowza.com/t/error-500-when-trying-to-add-new-stream-in-rest-api/52993
**Category:** Wowza Developer Dojo
**Created:** [March 13, 2019, 3:47pm UTC](https://community.wowza.com/t/error-500-when-trying-to-add-new-stream-in-rest-api/52993 "2019-03-13T15:47:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Marco\_Martello](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@Marco\_Martello](https://community.wowza.com/u/Marco_Martello)
#### Post date: [March 13, 2019, 3:47pm UTC](https://community.wowza.com/t/error-500-when-trying-to-add-new-stream-in-rest-api/52993/1 "2019-03-13T15:47:47Z")

</div>

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/](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”  
}

---

<div class="post-metadata">

### Author: ![Karel\_Boek](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/karel_boek/32/454_2.png) [@Karel\_Boek](https://community.wowza.com/u/Karel_Boek)
#### Post date: [March 13, 2019, 5:14pm UTC](https://community.wowza.com/t/error-500-when-trying-to-add-new-stream-in-rest-api/52993/2 "2019-03-13T17:14:18Z")

</div>

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](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](https://github.com/WowzaMediaSystems/wse-rest-library-php), so you don’t have to write your own implementation

---

<div class="post-metadata">

### Author: ![Emily\_Cambridge](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@Emily\_Cambridge](https://community.wowza.com/u/Emily_Cambridge)
#### Post date: [April 2, 2019, 4:01pm UTC](https://community.wowza.com/t/error-500-when-trying-to-add-new-stream-in-rest-api/52993/3 "2019-04-02T16:01:46Z")

</div>

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:

1. I’ve JSON encoded the data I’m sending for the stream
2. I’ve included the Content-Length (of my json encoded data) in my http headers
3. 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

```auto
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);

```
