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."
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

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.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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."
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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