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, source: https://github.com/sasjs/core
33 
34  <h4> SAS Macros </h4>
35  @li mp_abort.sas
36  @li mf_getplatform.sas
37  @li mf_getuniquefileref.sas
38  @li mf_getuniquelibref.sas
39 
40 **/
41 
42 %macro mv_getgroups(access_token_var=ACCESS_TOKEN
43  ,grant_type=sas_services
44  ,outds=work.viyagroups
45  );
46 %local oauth_bearer;
47 %if &grant_type=detect %then %do;
48  %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
49  %else %let grant_type=sas_services;
50 %end;
51 %if &grant_type=sas_services %then %do;
52  %let oauth_bearer=oauth_bearer=sas_services;
53  %let &access_token_var=;
54 %end;
55 %put &sysmacroname: grant_type=&grant_type;
56 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
57  and &grant_type ne sas_services
58  )
59  ,mac=&sysmacroname
60  ,msg=%str(Invalid value for grant_type: &grant_type)
61 )
62 
63 options noquotelenmax;
64 %local base_uri; /* location of rest apis */
65 %let base_uri=%mf_getplatform(VIYARESTAPI);
66 
67 /* fetching folder details for provided path */
68 %local fname1;
69 %let fname1=%mf_getuniquefileref();
70 %let libref1=%mf_getuniquelibref();
71 
72 proc http method='GET' out=&fname1 &oauth_bearer
73  url="&base_uri/identities/groups?limit=10000";
74  headers
75  %if &grant_type=authorization_code %then %do;
76  "Authorization"="Bearer &&&access_token_var"
77  %end;
78  "Accept"="application/json";
79 run;
80 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
81 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
82  ,mac=&sysmacroname
83  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
84 )
85 libname &libref1 JSON fileref=&fname1;
86 
87 data &outds;
88  set &libref1..items;
89 run;
90 
91 
92 
93 /* clear refs */
94 filename &fname1 clear;
95 libname &libref1 clear;
96 
97 %mend;