I know the 'PATCH' verb is not present in Apex and you have to override the method in the set header to PATCH with the following attribute: X-HTTP-Method-Override. I've done that but I still get a bad request (error code 400) response back.

I'm trying to make an http request to an Oracle cloud service. I've tested the exact same request in postman and it works fine. So in postman I set the request method as post but override it using the above header to PATCH and it works fine.

Below is the code snippet for reference. Also the endpoint URL is fine, I've checked that too.

        // define transaction variables
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http h = new Http();

        // Configure the request
        req.setEndpoint(endpoint + resource + '/' + OracleIssueId);
        System.debug('Endpoint:::: '+endpoint + resource + '/' + OracleIssueId);
        System.debug('Method:::: '+ method);

        // Add basic authentication to header
        // Create blob of user:pass
        Blob headerValue = Blob.valueOf(username + ':' + password);
        // Base 64 Encode the blob and prepend "Basic "
        String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
        // Add the basic auth string to the Request Header
        req.setHeader('Authorization', authorizationHeader);
        // Configure standard headers
        req.setHeader('Accept', '*/*');
        // This tells the API that we are sending and receiving the data as a JSON object 
        req.setHeader('Content-Type', 'application/json');

        // Set the request body json as key-value pairs
        String requestBody='{ '+
        '    "Source" : "'+Source+'",'+
        '    "Disposition" : "'+Disposition+'",'+
        '    "DispositionComment" : "'+Disposition_comment+'",'+
        '    "IssueEO_Subject_c" : "'+cs.OracleFetchFilter__c+'",'+
        '    "Severity": "'+Severity+'"'+ 

From where are you invoking it? If its from lightning then you need to create Named credential to store Endpoint and credentials. Then refer that endpoint here.


  • It is called from a trigger well the trigger calls a future method which does this and all the other GET and POSTmethods are working. It's just that this workaround for PATCH is throwing a 400 error. – Zarq Iqbal Jul 27 '19 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.