Deleting quote with REST API works fine in Postman and Swagger UI, fails silently with PHP curl

I’m trying to delete a quote from a PHP API connecting to Epicor’s REST API, using this standard HTTP DELETE method I found in the Swagger Api help UI:

“[…]api/v1/Erp.BO.QuoteSvc/Quotes/($companyName,$quoteNum)”

I can run this directly from the Swagger web GUI, and I get a 204 response, and can confirm the quote did in fact go away.
I can also quickly set up Postman to send a DELETE request to the same url, and it worked on the first try. Quote $quoteNum is gone. 204 response.

Then to my actual app…

  $delQuoteUrl = "[...]/api/v1/Erp.BO.QuoteSvc/Quotes/($companyName,$quoteN)";
  $curl = curl_init();

    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
    curl_setopt( $curl, CURLOPT_URL, $delQuoteURL );
    curl_setopt( $curl, CURLOPT_USERPWD, $uname . ":" . $pword );
    curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, "DELETE");

    $response = curl_exec( $curl );

    $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    curl_close( $curl );

Nope. It does not delete the quote.
It does not return any helpful information on why it didn’t delete the quote.
curl_error($curl) is false.
http response code is 0.

I tried using the same headers I used for the create quote command, both individually and all included:

curl_setopt( $curl, CURLOPT_HTTPHEADER,array('Content-Type:application/json;charset=utf-8','Accept:application/json','CallSettings:{"Company":"$companyName"}' ));

Which shouldn’t have been necessary, as Postman worked without setting those headers.
Also tried replacing the ‘CUSTOMREQUEST’ line with

    curl_setopt( $curl, CURLOPT_DELETE, true);

And tried setting CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER to false. Then tried setting them to true.

Anyway, none of it made any difference. No effect, no error message, no response code, nothing.
Now what? Am I missing anything obvious?

It’s been about 10 years since I looked at PHP, but you are passing the username and password without encoding it… does that matter? or is CURL doing the encoding for you?

What status code are you getting back? never mind I see you are getting 0… Zero means its not connecting to the server correctly.

Thanks- I know it’s not authentication that is the problem, because I’m already successfully creating quotes and quote details with a POST request. The PHP curl extension handles base64ing the username:password in the background, it doesn’t have to be done ahead of time.

If CURL is returning StatusCode of zero its a connection issue… as far as I can tell could you have mistyped the URL? Added extra slashes or not enough? Too many quotes (or note enough)

Thanks for all the help. I finally found my problem and it’s extremely stupid.

curl_setopt( $curl, CURLOPT_URL, $delQuoteURL );

‘$delQuoteUrl’ != ‘$delQuoteURL
:tired_face:

And I missed it because I had been returning $delQuoteUrl in the JSON response to the frontend to check that the URL was right. I would have expected a PHP error complaining about an undeclared variable but that didn’t happen.

1 Like