function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andre Baxter 7Andre Baxter 7 

Status=Forbidden, StatusCode=403] response when making an Apex callout

Hello community, I'm having an issue getting a positive response(200 code) when making a callout to SBA API.  I use the same authentication headers and endpoint in Postman and the response is successful.  However, currently that's not the case for me in Salesforce.  Below is my callout method code.  The JSON is in a separate method.  I have tried to do the callout without the body and headers and still receive the same response code.  Anyone ever run into this issue and resolved it?  Thanks.

public static string makeCallout(string jsonstring) {
        
        //call out logic here
        ETranDetails__c etranDetails =       ETranDetails__c.getOrgDefaults();
        HttpResponse response;
        
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setHeader('Authorization', etranDetails.API_Key__c);
        request.setHeader('Vendor-Key', etranDetails.Vendor_Key__c);
        request.setHeader('Content-Type', 'application/json');
        request.setEndpoint(etranDetails.Forgiveness_Endpoint__c);
        request.setMethod('POST');
        request.setTimeout(120000);
        request.setBody(jsonstring);
        response = http.send(request);
        
        return null;
    }
Best Answer chosen by Andre Baxter 7
Andre Baxter 7Andre Baxter 7
After comparing my Postman setup to my Apex code again, I realized that my endpoint was missing the "/api/ppp_loan_forgiveness_requests/" section at the end. After making that change, I no longer receive the 403 error code. Now I receive the 400 error code. That said, this question is resolved I say as 400 is a different issue. 

All Answers

AnudeepAnudeep (Salesforce Developers) 
Hi Andre, 

Can you create a dummy endpoint from hookbin and use it in your callout. That way we can check if there are any issues with the headers

Anudeep
Andre Baxter 7Andre Baxter 7

Hi Anudeep,
I created an endpoint in Hookbin, and used that endpoint in my code.  It returned with a positive status code of 200.  Hookbin didn't reveal any issues from what I saw.  However,  I do know that 403 stems from failure at authorization.  I've double and triple checked my vendor and api key.  They're identical to what I use in Post man, but so far, no successful responses in Salesforce when using the true endpoint.
Andre Baxter 7Andre Baxter 7
After comparing my Postman setup to my Apex code again, I realized that my endpoint was missing the "/api/ppp_loan_forgiveness_requests/" section at the end. After making that change, I no longer receive the 403 error code. Now I receive the 400 error code. That said, this question is resolved I say as 400 is a different issue. 
This was selected as the best answer