[SalesForce] PATCH request, always get 404 Not Found response

I am trying to update a value on my Salesforce record and integrate the date in another system using the Rest API. I am unable to do this using the PATCH request workaround in apex.

Booking__c reservation = [Select id,name,end__c,Impala_id__c from Booking__c 
                              where id=:reservationId];
DateTime dt = reservation.End__c;
dt = dt.addDays(1);
Integer endTime= dt.getTime().intValue()/1000;

HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + api_key);//some api key value
req.setHeader('Content-Type', 'application/json');
//req.setHeader('X-HTTP-Method-Override','PATCH');

req.setEndpoint('https://api.getimpala.com/v2/hotel/'+hotel_id+'/booking/'
                    +reservation.Impala_id__c+'?_HttpMethod=PATCH');
req.setBody('{"end":'+endTime+'}');
req.setMethod('POST');
Http http = new Http();
HTTPResponse res2 = http.send(req);
system.debug('status is: '+res2.getStatus());
system.debug('status is: '+res2.getStatusCode());

I tried using both the options (1-using header and 2-appending in url). whereas in postman this is working fine which means endpoint is up and running.
enter image description here

Best Answer

HttpRequest doesn't support PATCH as the method. From the docs:

Possible values for the method type include:


DELETE
GET
HEAD
POST
PUT
TRACE

Setting X-HTTP-Method-Override header to PATCH is a workaround some services support if a client can't issue a PATCH request. Docs for getimpala.com APIs do not mention this option nor do they mention appending _HttpMethod=PATCH to the endpoint as a possibility.

Recommendation: send a POST request to a proxy that lives outside of Salesforce, then have the proxy rewrite POST to PATCH, send the PATCH request to getimpala.com, grab the response and send the response back to Salesforce. Lots of proxies can do this, e.g. here's how it works with HAProxy.