Macros for SAS Application Developers
https://github.com/sasjs/core
mv_getusers.sas
Go to the documentation of this file.
1 /**
2  @file mv_getusers.sas
3  @brief Creates a dataset with a list of users
4  @details First, be sure you have an access token (which requires an app token)
5 
6  Using the macros here:
7 
8  filename mc url
9  "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
10  %inc mc;
11 
12  An administrator needs to set you up with an access code:
13 
14  %mv_registerclient(outds=client)
15 
16  Navigate to the url from the log (opting in to the groups) and paste the
17  access code below:
18 
19  %mv_tokenauth(inds=client,code=wKDZYTEPK6)
20 
21  Now we can run the macro!
22 
23  %mv_getusers(outds=users)
24 
25  Output (lengths are dynamic):
26 
27  ordinal_root num,
28  ordinal_items num,
29  version num,
30  id char(20),
31  name char(23),
32  providerId char(4),
33  type char(4),
34  creationTimeStamp char(24),
35  modifiedTimeStamp char(24),
36  state char(6)
37 
38  @param [in] access_token_var= (ACCESS_TOKEN)
39  The global macro variable to contain the access token
40  @param [in] grant_type= (sas_services) Valid values:
41  * password
42  * authorization_code
43  * detect - will check if access_token exists, if not will use sas_services
44  if a SASStudioV session else authorization_code.
45  * sas_services - will use oauth_bearer=sas_services
46 
47  @param [out] outds= (work.mv_getusers)
48  The library.dataset to be created that contains the list of groups
49 
50 
51  @version VIYA V.03.04
52  @author Allan Bowe, source: https://github.com/sasjs/core
53 
54  <h4> SAS Macros </h4>
55  @li mp_abort.sas
56  @li mf_getplatform.sas
57  @li mf_getuniquefileref.sas
58  @li mf_getuniquelibref.sas
59 
60 **/
61 
62 %macro mv_getusers(outds=work.mv_getusers
63  ,access_token_var=ACCESS_TOKEN
64  ,grant_type=sas_services
65  );
66 %local oauth_bearer;
67 %if &grant_type=detect %then %do;
68  %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
69  %else %let grant_type=sas_services;
70 %end;
71 %if &grant_type=sas_services %then %do;
72  %let oauth_bearer=oauth_bearer=sas_services;
73  %let &access_token_var=;
74 %end;
75 %put &sysmacroname: grant_type=&grant_type;
76 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
77  and &grant_type ne sas_services
78  )
79  ,mac=&sysmacroname
80  ,msg=%str(Invalid value for grant_type: &grant_type)
81 )
82 
83 options noquotelenmax;
84 
85 %local base_uri; /* location of rest apis */
86 %let base_uri=%mf_getplatform(VIYARESTAPI);
87 
88 /* fetching folder details for provided path */
89 %local fname1;
90 %let fname1=%mf_getuniquefileref();
91 %let libref1=%mf_getuniquelibref();
92 
93 proc http method='GET' out=&fname1 &oauth_bearer
94  url="&base_uri/identities/users?limit=10000";
95 %if &grant_type=authorization_code %then %do;
96  headers "Authorization"="Bearer &&&access_token_var"
97  "Accept"="application/json";
98 %end;
99 %else %do;
100  headers "Accept"="application/json";
101 %end;
102 run;
103 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
104 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
105  ,mac=&sysmacroname
106  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
107 )
108 libname &libref1 JSON fileref=&fname1;
109 
110 data &outds;
111  set &libref1..items;
112 run;
113 
114 /* clear refs */
115 filename &fname1 clear;
116 libname &libref1 clear;
117 
118 %mend mv_getusers;