Production Ready 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 access_token_var= The global macro variable to contain the access token
39 @param grant_type= valid values:
40 * password
41 * authorization_code
42 * detect - will check if access_token exists, if not will use sas_services if
43 a SASStudioV session else authorization_code. Default option.
44 * sas_services - will use oauth_bearer=sas_services
45
46 @param outds= The library.dataset to be created that contains the list of groups
47
48
49 @version VIYA V.03.04
50 @author Allan Bowe, source: https://github.com/sasjs/core
51
52 <h4> SAS Macros </h4>
53 @li mp_abort.sas
54 @li mf_getplatform.sas
55 @li mf_getuniquefileref.sas
56 @li mf_getuniquelibref.sas
57
58**/
59
60%macro mv_getusers(outds=work.mv_getusers
61 ,access_token_var=ACCESS_TOKEN
62 ,grant_type=sas_services
63 );
64%local oauth_bearer;
65%if &grant_type=detect %then %do;
66 %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
67 %else %let grant_type=sas_services;
68%end;
69%if &grant_type=sas_services %then %do;
70 %let oauth_bearer=oauth_bearer=sas_services;
71 %let &access_token_var=;
72%end;
73%put &sysmacroname: grant_type=&grant_type;
74%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
75 and &grant_type ne sas_services
76 )
77 ,mac=&sysmacroname
78 ,msg=%str(Invalid value for grant_type: &grant_type)
79)
80
81options noquotelenmax;
82
83%local base_uri; /* location of rest apis */
84%let base_uri=%mf_getplatform(VIYARESTAPI);
85
86/* fetching folder details for provided path */
87%local fname1;
88%let fname1=%mf_getuniquefileref();
89%let libref1=%mf_getuniquelibref();
90
91proc http method='GET' out=&fname1 &oauth_bearer
92 url="&base_uri/identities/users?limit=10000";
93%if &grant_type=authorization_code %then %do;
94 headers "Authorization"="Bearer &&&access_token_var"
95 "Accept"="application/json";
96%end;
97%else %do;
98 headers "Accept"="application/json";
99%end;
100run;
101/*data _null_;infile &fname1;input;putlog _infile_;run;*/
102%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
103 ,mac=&sysmacroname
104 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
105)
106libname &libref1 JSON fileref=&fname1;
107
108data &outds;
109 set &libref1..items;
110run;
111
112/* clear refs */
113filename &fname1 clear;
114libname &libref1 clear;
115
116%mend mv_getusers;