[Spce-user] REST API customer terminate not working...

Walter Klomp walter at myrepublic.net
Sat May 12 03:34:55 EDT 2018


Hi,

OK, thank you for the tip. Now it works!

Thanks,
Walter



> On 12 May 2018, at 2:21 AM, Irina Peshinskaya <ipeshinskaya at sipwise.com> wrote:
> 
> Dear Walter,
> 
> Here is example of command line curl call to terminate customer:
> 
> root at sp1:~# curl -i -k -X PATCH -H 'Connection: close' -H 'Content-Type: application/json-patch+json'  --user administrator:administrator 'https://127.0.0.1:1443/api/customers/221 <https://127.0.0.1:1443/api/customers/221>' --data-binary '[{ "op" : "replace", "path" : "/status", "value" : "terminated" }]'
> HTTP/1.1 204 No Content
> Server: nginx
> Date: Fri, 11 May 2018 18:17:08 GMT
> Connection: close
> Preference-Applied: return=minimal
> Set-Cookie: ngcp_panel_session=826f204486c1123b1af0a7482d7735cdde1e889b; path=/; expires=Fri, 11-May-2018 19:17:07 GMT; HttpOnly
> X-Catalyst: 5.90114
> Strict-Transport-Security: max-age=15768000
> 
> root at sp1:~#
> 
> 
> I see the difference that your content is JSON object, but API expects an array of objects, like in example. So
> 
>                 $jsonDataEncoded = "{ 'op' : 'replace', 'path' : '/status', 'value' : 'terminated' }";
> 
> should be
> 
>                 $jsonDataEncoded = "[ { 'op' : 'replace', 'path' : '/status', 'value' : 'terminated' } ]";
> 
> Best regards,
> Irina Peshinskaya
> 
> On 2018-05-11 18:30, Walter Klomp wrote:
>> Hi,
>> 
>> I require a bit of help. I am trying to write some modules to convert from SOAP to rest and I am following the example on
>> 
>> https://www.sipwise.com/doc/mr6.2.1/spce/ar01s10.html <https://www.sipwise.com/doc/mr6.2.1/spce/ar01s10.html> , but then in PHP…  
>> 
>> I have managed to write the create contact, customer and subscriber, and set preferences, but now I am trying to DELETE them, and I get no response on that request…
>> 
>> Below is the snippet of code I am executing…. 
>> 
>> 
>> 		echo "Terminating customer id $customer_id ...";
>> 
>>                 $url = "https://$host:1443/api/customers/$customer_id <https://$host:1443/api/customers/$customer_id>";
>> 
>>                 //Initiate cURL.
>>                 $ch = curl_init($url);
>> 
>>                 //The JSON data.
>>                 $jsonDataEncoded = "{ 'op' : 'replace', 'path' : '/status', 'value' : 'terminated' }";
>> 
>>                 curl_setopt($ch, CURLOPT_USERPWD,”$user:$pw");
>>                 curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
>> 
>>                 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
>> 
>>                 //Attach our encoded JSON string to the POST fields.
>>                 curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
>> 
>>                 //Set the content type to application/json
>>                 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
>>                 curl_setopt($ch, CURLOPT_HEADER, TRUE);
>> 
>> /*
>>   Let's get the Response !
>> */
>> $api_response = curl_exec($ch);
>> 
>> /*
>>   We need to get Curl infos for the header_size and the http_code
>> */
>> $api_response_info = curl_getinfo($ch);
>> /*
>>   Here we separate the Response Header from the Response Body
>> */
>> $api_response_header = trim(substr($api_response, 0, $api_response_info['header_size']));
>> $api_response_body = substr($api_response, $api_response_info['header_size']);
>> 
>> // Response HTTP Status Code
>> echo $api_response_info['http_code'];
>> 
>> // Response Header
>> echo $api_response_header;
>> 
>> // Response Body
>> echo $api_response_body;
>> 
>> exit;
>> 
>> 
>> 
>> ———
>> 
>> I know the customer_id is a valid number, but I get no response from the server, http_code=0, and nothing in the headers and body.  (which is why I put the extended code in) - I also see nothing in API.php.     I have even checked if the username of the account is “master”, and it is, so it should have the right to do this.
>> 
>> Am I missing something ?   Do I need to set something somewhere to enable deletion ?
>> 
>> Hope anybody can help.
>> 
>> Thank you
>> Walter Klomp
>> 
>> 
>> 
>> 
>> 
>> 
>> Warmest Regards,
>> 
>>  <https://myrepublic.com.sg/>	
>> Walter Klomp
>> Head of Voice
>> MyRepublic Limited
>> T: +65 6816 1120
>> F: +65 6717 2031
>>  
>> MyRepublic Limited
>> 11 Lorong 3 Toa Payoh Block B Jackson Square
>> #04-11/15 Singapore 319579
>> 
>> myrepublic.com.sg <https://myrepublic.com.sg/>
>> Follow us on: Twitter <https://twitter.com/myrepublic> | Facebook <https://facebook.com/myrepublicsg> | LinkedIn <https://www.linkedin.com/company/myrepublic>
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Spce-user mailing list
>> Spce-user at lists.sipwise.com <mailto:Spce-user at lists.sipwise.com>
>> https://lists.sipwise.com/listinfo/spce-user <https://lists.sipwise.com/listinfo/spce-user>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sipwise.com/pipermail/spce-user_lists.sipwise.com/attachments/20180512/61e7b138/attachment-0001.html>


More information about the Spce-user mailing list