Search code examples
phpapicurlvoice

PHP VoiceCloud API return ERROR


I'm using VOICECLOUD API for transcription (Voice to Text). I call the API using CURL.

the result/response is: (-5 could not save file ) with no more details :(

Here is my code:

function CallAPI($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);

    print_r($result); //Always returns:  -5 could not save file 
}

$url = 'http://api.voicecloud.com/api.cgi?action=sendfile&username=MY+USER+NAME&devkey=11xxxx&idtype=username&fileurl=http://www.EXAMPLE.com/app/recordings/test.mp3&filetype=mp3&callerid=18xxxxxxxx';
CallAPI($url);  

Solution

  • The API states that you should pass the parameters by GET.

    So change your $data array like

    $val=http_build_query($data);
    $url='http://api.voicecloud.com/api.cgi';
    $url.=$val;//Appending the params to the URL
    

    and change your CALLAPI() like

    function CallAPI($method, $url, $data = false) {
        $curl = curl_init();
        //curl_setopt($curl, CURLOPT_POST, 1);//Commmented
        //curl_setopt($curl, CURLOPT_POSTFIELDS, $data);//Commented
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($curl);
    
        print_r($result);
        curl_close($curl);
    }