Search code examples
phpcurlwowzaphp-curlwowza-transcoder

Wowza Cloud API: curl requests


I can't make it work.. :( I have this function (for create passthrough transcoder), when I run I see NULL in the web. If I test directly from the browser with the url, it does notify me that there is a problem an auth (apikey and acceskey)

function createPassthrough($name, $source_url, $recording = null)
{
    $url = "https://sandbox.cloud.wowza.com/api/v1/transcoders";

    $json = '{
                "transcoder":{
                    "billing_mode":"pay_as_you_go",
                    "broadcast_location":"eu_belgium",
                    "delivery_method":"pull",
                    "name":"prueba",
                    "protocol":"rtsp",
                    "source_url":"url_camara",
                    "transcoder_Type":"passthrough",
                    "low_latency":true,
                    "buffer_size":0,
                    "play_maximum_connections":100,
                    "stream_smoother":false
                    }
            }';

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept:application/json; charset=utf-8',
        'Content-Type: application/json; charset=utf-8',
        'wsc-api-key:' . $apiKey,
        'wsc-access-key:' . $accessKey,
    ));

    $result = curl_exec($ch);
    curl_close($ch);

    $obj = json_decode($result);
    var_dump($obj);
}

What am I doing wrong? Thanks in advance.


Solution

  • You should check for curl errors after $result = curl_exec($ch);.

    // Check for errors and display the error message
    if($errno = curl_errno($ch)) {
        $error_message = curl_strerror($errno);
        echo "cURL error ({$errno}):\n {$error_message}";
    }