problem with curl in php on ring-out

  • 1
  • Problem
  • Updated 3 months ago

$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" : [ ] 
}
Photo of Andrew Auger

Andrew Auger

  • 102 Points 100 badge 2x thumb

Posted 3 months ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 9,486 Points 5k badge 2x thumb
Please use

from: { phoneNumber: '+12048184079' } 

instead of

from: '+12048184079'
Photo of Phong Vu

Phong Vu, Devangelist

  • 4,966 Points 4k badge 2x thumb
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