function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AbAb 

Apex API code for token with basic authentification (username )

Hello,

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 Ab
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);

Thanks,
Maharajan.C