+ Start a Discussion

Apex API code for token with basic authentification (username )


I want to get a token from the end point:
User-added image
For passing parameters in end point i have Authorization, Header and Body.

Ho can i write the code for the Authorization part, Authorization type = basic, User name and password, etc 

I already have written code for header and body

thank you for suggestion !
Best Answer chosen by Sandrine
Maharajan CMaharajan C
Hi Sandrine,

Try to add the below lines for auth header.

HTTPRequest req = new HTTPRequest();
Blob headerValue = Blob.valueOf(username+':'+password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);