After several tries, I have found the solution, I was looking for. I am sharing it with the community. The task is to obtain via an API call, a Bearer Token but by providing the Basic Authentication. So, the first step is to convert the client_id and the client_secret using a base64 encoder to obtain a base64-encoded string, i.e., the Basic Authentication value (&Basic_Auth, in the SAS code below) Thereafter, a proc http call is done, providing the above-mentioned Basic Authentication value, to the appropriate web site, to obtain a Bearer Token. This Bearer Token is replacing the use of an API Token and the difference is that this Bearer Token is valid only for a certain period.
%macro BearerToken(client_id, client_secret); /* Example of call: %BearerToken(&client_id., &client_secret.); */
/* Reading the input values */
%put reading the input values: &=client_id &=client_secret;
/**** Converting the Client_id and the client_secret using base64 encoder to obtain the corresponding Basic Authentication value ***/
data _null_;
length newString $200.;
newString=cats("&client_id.",":","&client_secret.");
call symputx('Basic_Auth',put(trim(newString),$base64x300.));
run;
%put &=Basic_Auth;
/* Sending the Basic Authentication value to the appropriate web site, via an API call to obtain the Bearer_token ****/
options set=SSLREQCERT="allow";
filename resp temp;
/* must include content-type/CT= option */
proc http
url="https://ca1.qualtrics.com/oauth2/token"
method='POST'
AUTH_BASIC
AUTH_NEGOTIATE
ct="application/x-www-form-urlencoded"
in='grant_type=client_credentials&scope=read:survey_responses'
out=resp;
headers "Authorization" = "Basic &Basic_Auth.";
;
run;
/* Checking the log for the API Call */
%put &=SYS_PROCHTTP_STATUS_CODE;
data _null_;
rc=jsonpp('resp','log');
run;
/* Getting the Bearer Token */
libname auth json fileref=resp;
data _null_;
set auth.root;
call symputx('BearerToken',access_token,'g');
run;
%put &=BearerToken;
%mend BearerToken;
%BearerToken(&client_id., &client_secret.);
... View more