BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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);
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Try:

 

%let scope = manage:all;

in="grant_type=client_credentials%str(&)scope=&scope."
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

View solution in original post

3 REPLIES 3
ChrisHemedinger
Community Manager

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.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
alepage
Barite | Level 11

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 ?

 

 

ChrisHemedinger
Community Manager

Try:

 

%let scope = manage:all;

in="grant_type=client_credentials%str(&)scope=&scope."
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1134 views
  • 0 likes
  • 2 in conversation