question

andrew-auger avatar image
andrew-auger asked ·

problem with curl in php on ring-out


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL," https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/ring-out");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 
        http_build_query(array('from' => '+12048184079',
                              'to' => '+17604762222'
                                    )));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
           "Content-Type: application/json",
           "Accept: application/json",
           "Authorization: Bearer U0pDMTFQMDFQQVMwMHxBQUFtdWhQcG5lYk4xbUIwc2pyaXpqTVZJZnlxUWhENlEtc2NRcTNxYmZaRXl5Qk9nSWk2RDFiMjVFTy0zaXhsVGlWNF9QWWRPMEVYNENYQjd4dmJsWHJoVTBsTVl2VlA1XzNIczcycTVONm13eDY5d3o3YWkwN3l5Wkt3clFLVDl0Y3FmajJQZ0tRSUtmRnhjNGJua1lHbmxxSElJTzBnOUxab0dZR19MVlo5bGhDU2pMcE1oYm5jRG9icVRYbUswSm14VzI3VmdrNjR2aVZxUGt6bU9aOUN8amhaMGtnfFZFM1ZGamhpaTdKcjc2dkRzSDEzMGd8QUE"
            
               ];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$server_output = curl_exec($ch);

echo "<pre>"; print_r($server_output); die;

curl_close ($ch);



output: -


{    "errorCode" : "InvalidJson",    "message" : "Unrecognized token 'from': was expecting 'null', 'true', 'false' or NaN\n at line: 1, column: 6",    "errors" : [ ] 
}
topic-default
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered ·
Please use

from: { phoneNumber: '+12048184079' } 

instead of

from: '+12048184079'
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered ·
Hi Andrew,

The content type is "application/json". Here is the way to create the body for the API call

$params = array(
        'from' => array('phoneNumber' => '+12048184079'),
        'to' => array('phoneNumber' => '+17604762222')
        );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));


+ Phong
   
Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.