Question

problem with curl in php on ring-out

  • 16 January 2019
  • 2 replies
  • 1676 views


$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
 at line: 1, column: 6",    "errors" : [ ] 

}


2 replies

Please use

from: { phoneNumber: '+12048184079' } 

instead of

from: '+12048184079'
Userlevel 1
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
   

Reply