I have a basic auth which I have working with Postman but when I do this with apex I get an Forbidden error. The variables userKeyVal and userSecretVal are filled correctly, my url is correct and I granted acces trough remote site setings. What am I missing.
Postman
**Key** **Value**
Content-Type application/json
Authorization Basic AAAAAAAAAAAAAAAAAAAAAAAAAAA==
Update(not needed):
client_id 123456789
client_secret BBBBBBBBBBBBBBBBBBBB
Apex
@TestVisible static Boolean doCallout = true;
@future(callout=true)
//Get Stock
public static void getStock() {
if(doCallout) {
fetchConfiguration();
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(UrlVal +'stock/?');
request.setMethod('GET');
request.setHeader('Content-Type','application/json');
Blob headerValue = Blob.valueOf(userKeyVal + ':' + userSecretVal);
String authorizationHeader = 'BASIC ' +EncodingUtil.base64Encode(headerValue);
request.setHeader('Authorization', authorizationHeader);
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200) {
System.debug('response: ' + response);
}
}
}
request.setHeader('client_id', '123456789');
andrequest.setHeader('client_secret', 'BBBBBBBBBBBBBBBBBBBB');