You need to sign in to do that
Don't have an account?
403 Forbidden Error when calling API
Hi Guys,
I'm trying to call an external API using a http class which looks like this:
String jsonBody = '{"CoverState":"NSW","CoverType":"S","HospitalProductId":29,"ExtrasProductId":34,"RebateFlag":"N","EffectiveDate":"12/02/2017","BillingFrequency":1,"Member1Age":0,"Member2Age":0,"payDirectDebit":"Y","maxAge":53,"rebateTier":3,"groupingid":0,"member1lhcPercentage":"46","member2lhcPercentage":"0","RebatePercent":0}';
String requestBody = JSON.serializePretty(jsonBody);
Http h = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setEndpoint('http://10.x.x.xxx:xxxx/xxx/xxxx/xxxx');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setBody(requestBody);
System.Debug('@@@ req.getHeader'+req.getHeader('req.getHeader; '+'Content-Length'));
System.Debug('@@@ req: '+req);
System.Debug('@@@ req.getBody'+req.getBody());
res = h.send(req);
System.Debug('@@@ res: === '+res);
String auth = res.getBody();
System.Debug('@@@ Debug(auth:'+auth);
It's giving me a 403 forbidden error when a send this using the dev console in Salesforce.
I've set up a remote access URL in Salesforce and also enabled API for my account.
If anyone could help that would be greatly appreciated.
Cheers,
Corey
There might be some issue in your Service URL - http://10.x.x.xxx:xxxx/xxx/xxxx/xxxx
First Check is the URL is HTTP or HTTPS. Then try to do a simple call without any header,body and check response.