+ Start a Discussion
Etienne Gaudry 5Etienne Gaudry 5 

401 API

Hi, i try to make a post API call.
On Postman with the wrapper and the token of my method, my api call work. The endpoint is good too. But on apex i have 401 error.

I think my SetHeader is bad :

request.setHeader('Authorization', 'oAuth 2.0 ' + accToken);
request.setHeader('Content-Type', 'application/json');
request.setHeader('Accept','*/*');
request.setBody(JSON.serialize(resWrap));
request.setMethod('POST');
request.setEndpoint(endPoint);
HttpResponse hresponse = htt.send(request);
system.debug(hresponse);

i have this response, ty for helping :
System.HttpResponse[Status=Non-Autorisé, StatusCode=401]
GovindarajGovindaraj
Hi Etienne,

Please modify 1st line like below,

request.setHeader('Authorization','Bearer '+accToken);

it should be bearer and not oAuth 2.0

Please let us know, if this helps.

Thanks,
Govindaraj.S
Jakub Kołodziej 7Jakub Kołodziej 7
Did you add endpoint to Remote Sites in Setup?