0

Can anyone let me know how to use http delete method. am trying to achieve that using curl but it is giving http code 0 which i don't understand. can anyone please tel me what else need to be added to the bellow code

$url = 'https://api.rezdy.com/v1/bookings/R1Z8HKV/?apiKey=f125ad643aff4cbe98043302424a###';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
$api_response = curl_exec($ch); 
$api_response_info = curl_getinfo($ch); 
curl_close($ch);
$api_response_header = trim(substr($api_response, 0, $api_response_info['header_size']));
$api_response_body = substr($api_response, $api_response_info['header_size']);
echo $api_response_info['http_code'];
echo "<br><br>";
echo $api_response_header;
echo "<br><br>";
echo $api_response_body;
echo "<br><br>";
Umesh M Gowda
  • 121
  • 1
  • 13
  • There is no HTTP code of value "0". So something is wired here, perhaps the server is returning an invalid response message. Hard to say more from what is shared in the question alone. – hakre Jun 14 '17 at 08:19
  • am suppose to delete a booking in rest API for which i need to call http delete method. – Umesh M Gowda Jun 14 '17 at 08:21
  • For the example you have here, I get the HTTP status code 403 (forbidden) and the response body is `{"requestStatus":{"success":false,"error":{"errorCode":"6","errorMessage":"Invalid API Key"}}}`. No reproduceable. – hakre Jun 14 '17 at 08:29
  • 1
    Gives response code 200 which seems fine. Response body looks good, too: `{"success":true,"warning":{"warningMessage":"This order is already cancelled"},"version":"v1"}, ...`. – hakre Jun 14 '17 at 09:01
  • did u used the same code. which i posted above. – Umesh M Gowda Jun 14 '17 at 09:04
  • Exactly the same code verbatim, just copy and paste. – hakre Jun 14 '17 at 09:05
  • then do you think the browser is the one which is not supporting or what could be the reason it is not working for me. – Umesh M Gowda Jun 14 '17 at 09:06
  • 1
    That's hard to say and would lead to guessing. Guessing is not working well for debugging, only do it in the first 3-5 minutes. After that, if guessing was not taking you to a solution, start with proper debugging. E.g. start to isolate the problem (which you technically did with posting it as a question here with a reduced PHP script, all I can say is that the code you've posted works, so the error must be elsewhere, could be a comparison done wrong or data-loss when you further process the response data). – hakre Jun 14 '17 at 09:11
  • Thank you so much hakre, the problem was the environment. i was trying to execute the code in local wamp server for some other reason it is not working but when i execute the same code on the server it worked well. i don not know what exactly is troubling in local wamp server; but yes your suggestion helped me a lot thank you. – Umesh M Gowda Jun 14 '17 at 09:29
  • Curl might make use of some environment variables, e.g. some proxy settings. That can be a difference in the environment I know about, but I can not precisely say what is causing this in your case.Also there is PHP configuration for each each module. – hakre Jun 14 '17 at 09:49

0 Answers0