+ Start a Discussion
ChemburChembur 

REST API 403 - Forbidden error

I have 'unlimited Edition' and API enable and running as system administrator.

I have a REST API wil endpoint 'http://mycompany.com/test. I have set this URL as Remote site setting

 

The code to execute REST is below.. When  I execute the code from ny sandbox I get 403 Forbidden error. Any help appreciated

 

HttpRequest request = new HttpRequest();
        HttpResponse response = new HttpResponse();
        Http http = new Http();
        
        JSONGenerator jsonGen = JSON.createGenerator(true);
        jsonGen.writeStartObject();
        jsonGen.writeStringfield('testString', '12345');
        jsonGen.writeEndObject();
        String jsonPro = jsonGen.getAsString();
        system.debug('jsonPro ' + jsonPro);
       
        request.setMethod('POST');
        request.setEndpoint('http://xx.xx.xx.xxx:xxxxx');
        request.setHeader('Content-Type', 'application/JSON');
        request.setBody(jsonPro);
        try{
            response = http.send(request);
        } catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug(response.toString());
        }      
        if (response.getStatusCode() != 200){
            System.debug('Error from endpoint ' + request.getEndpoint() + ' code ' + response.getStatusCode() + ' Status ' + response.getStatus());         
            throw new RestException();
        }else{   
             system.debug('********** RESPONSE body SUCCESS !!! ' + response.getBody());
        }
       

Sonam_SFDCSonam_SFDC

Hi Chembur,

 

What is the exact error message shown in the response for 403 Forbidden Error :

check this similar post(http://boards.developerforce.com/t5/forums/forumtopicprintpage/board-id/integration/message-id/1655/print-single-message/true/page/1)

ChemburChembur

thanks for the reply, it was a firewall issue. SFDC cannot call the REST API into our network unless the REST API is exposed outside our firewall.