Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mv_getgroups.sas
Go to the documentation of this file.
1 /**
2  @file mv_getgroups.sas
3  @brief Creates a dataset with a list of viya groups
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_getgroups()
24 
25  @param access_token_var= The global macro variable to contain the access token
26  @param grant_type= valid values are "password" or "authorization_code" (unquoted).
27  The default is authorization_code.
28  @param outds= The library.dataset to be created that contains the list of groups
29 
30 
31  @version VIYA V.03.04
32  @author Allan Bowe
33  @source https://github.com/sasjs/core
34 
35  <h4> Dependencies </h4>
36  @li mp_abort.sas
37  @li mf_getplatform.sas
38  @li mf_getuniquefileref.sas
39  @li mf_getuniquelibref.sas
40 
41 **/
42 
43 %macro mv_getgroups(access_token_var=ACCESS_TOKEN
44  ,grant_type=sas_services
45  ,outds=work.viyagroups
46  );
47 %local oauth_bearer;
48 %if &grant_type=detect %then %do;
49  %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
50  %else %let grant_type=sas_services;
51 %end;
52 %if &grant_type=sas_services %then %do;
53  %let oauth_bearer=oauth_bearer=sas_services;
54  %let &access_token_var=;
55 %end;
56 %put &sysmacroname: grant_type=&grant_type;
57 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
58  and &grant_type ne sas_services
59  )
60  ,mac=&sysmacroname
61  ,msg=%str(Invalid value for grant_type: &grant_type)
62 )
63 
64 options noquotelenmax;
65 %local base_uri; /* location of rest apis */
66 %let base_uri=%mf_getplatform(VIYARESTAPI);
67 
68 /* fetching folder details for provided path */
69 %local fname1;
70 %let fname1=%mf_getuniquefileref();
71 %let libref1=%mf_getuniquelibref();
72 
73 proc http method='GET' out=&fname1 &oauth_bearer
74  url="&base_uri/identities/groups?limit=10000";
75  headers
76  %if &grant_type=authorization_code %then %do;
77  "Authorization"="Bearer &&&access_token_var"
78  %end;
79  "Accept"="application/json";
80 run;
81 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
82 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
83  ,mac=&sysmacroname
84  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
85 )
86 libname &libref1 JSON fileref=&fname1;
87 
88 data &outds;
89  set &libref1..items;
90 run;
91 
92 
93 
94 /* clear refs */
95 filename &fname1 clear;
96 libname &libref1 clear;
97 
98 %mend;