I would like to pass the scope as parameter but up to now it failed. Please note that the credential.sas file contains : client_id,client_secret, scope as global macro variable.
I want to replace this statement which works
in='grant_type=client_credentials&scope=manage:all'
for in='grant_type=client_credentials&scope= &scope.'
But the above line those not work.
/finsys/.../TEST/Credentials.sas
%macro BearerToken(client_id, client_secret,scope);
/* Example of call: %BearerToken(&client_id., &client_secret.); */
/* For debugging only ! 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.),'g');
run;
/* For debugging only !
%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 read:users'*/
/*in='grant_type=client_credentials&scope=manage:all'*/
in=%str(') grant_type=client_credentials&scope= &scope %str(')
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;
%global Bearertimer_start BTExpIn;
data BearerInfo;
set auth.root;
%let Bearertimer_start = %sysfunc(datetime());
call symputx('BearerToken',access_token,'g');
call symput('BTExpIn',expires_in);
call symputx('BearerTokenValid','Yes','g');
run;
%put &=BearerToken. &=BTExpIn. &=Bearertimer_start.;
%mend BearerToken;
% BearerToken(&client_id, &client_secret, &scope);
Try:
%let scope = manage:all;
in="grant_type=client_credentials%str(&)scope=&scope."
If you want the &scope macro variable to be resolved, the IN= value must be in double quotes. Using single quotes will prevent the macro processor from resolving the value.
could you please provide an example
I have tried:
/*in='grant_type=client_credentials&scope=manage:all'*/
/*in="grant_type=client_credentials&scope=&scope"*/
in="grant_type=client_credentials&scope=manage:all"
The only one that is working is :
in='grant_type=client_credentials&scope=manage:all'
%let scope=manage:all;
So I need to find a way to reproduce this string: 'grant_type=client_credentials&scope=manage:all'
by passing &scope and remember that the first &scope should not be interpreted as a macro variable . How to do that ?
Try:
%let scope = manage:all;
in="grant_type=client_credentials%str(&)scope=&scope."
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.