Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mv_getfoldermembers.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Gets a list of folder members (and ids) for a given root
4 @details Returns all members for a particular Viya folder. Works at both root
5 level and below, and results are created in an output dataset.
6
7 %mv_getfoldermembers(root=/Public, outds=work.mymembers)
8
9
10 @param [in] root= (/) The path for which to return the list of folders
11 @param [out] outds= (work.mv_getfolders) The output dataset to create. Format:
12 |ordinal_root|ordinal_items|creationTimeStamp| modifiedTimeStamp|createdBy|modifiedBy|id| uri|added| type|name|description|
13 |---|---|---|---|---|---|---|---|---|---|---|---|
14 |1|1|2021-05-25T11:15:04.204Z|2021-05-25T11:15:04.204Z|allbow|allbow|4f1e3945-9655-462b-90f2-c31534b3ca47|/folders/folders/ed701ff3-77e8-468d-a4f5-8c43dec0fd9e|2021-05-25T11:15:04.212Z|child|my_folder_name|My folder Description|
15
16 @param [in] access_token_var= (ACCESS_TOKEN) The global macro variable to
17 contain the access token
18 @param [in] grant_type= (sas_services) Valid values are:
19 @li password
20 @li authorization_code
21 @li detect
22 @li sas_services
23
24 @version VIYA V.03.04
25 @author Allan Bowe, source: https://github.com/sasjs/core
26
27 <h4> SAS Macros </h4>
28 @li mp_abort.sas
29 @li mf_getplatform.sas
30 @li mf_getuniquefileref.sas
31 @li mf_getuniquelibref.sas
32 @li mf_isblank.sas
33
34 <h4> Related Macros </h4>
35 @li mv_createfolder.sas
36 @li mv_deletefoldermember.sas
37 @li mv_deleteviyafolder.sas
38 @li mv_getfoldermembers.test.sas
39
40**/
41
42%macro mv_getfoldermembers(root=/
43 ,access_token_var=ACCESS_TOKEN
44 ,grant_type=sas_services
45 ,outds=mv_getfolders
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
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%if %mf_isblank(&root)=1 %then %let root=/;
65
66options noquotelenmax;
67
68/* request the client details */
69%local fname1 libref1;
70%let fname1=%mf_getuniquefileref();
71%let libref1=%mf_getuniquelibref();
72
73%local base_uri; /* location of rest apis */
74%let base_uri=%mf_getplatform(VIYARESTAPI);
75
76%if "&root"="/" %then %do;
77 /* if root just list root folders */
78 proc http method='GET' out=&fname1 &oauth_bearer
79 url="&base_uri/folders/rootFolders?limit=1000";
80 %if &grant_type=authorization_code %then %do;
81 headers "Authorization"="Bearer &&&access_token_var";
82 %end;
83 run;
84 libname &libref1 JSON fileref=&fname1;
85 data &outds;
86 set &libref1..items;
87 run;
88%end;
89%else %do;
90 /* first get parent folder id */
91 proc http method='GET' out=&fname1 &oauth_bearer
92 url="&base_uri/folders/folders/@item?path=&root";
93 %if &grant_type=authorization_code %then %do;
94 headers "Authorization"="Bearer &&&access_token_var";
95 %end;
96 run;
97 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
98 libname &libref1 JSON fileref=&fname1;
99 /* now get the followon link to list members */
100 %local href cnt;
101 %let cnt=0;
102 data _null_;
103 length rel href $512;
104 call missing(rel,href);
105 set &libref1..links;
106 if rel='members' then do;
107 url=cats("'","&base_uri",href,"?limit=10000'");
108 call symputx('href',url,'l');
109 call symputx('cnt',1,'l');
110 end;
111 run;
112 %if &cnt=0 %then %do;
113 %put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
114 %return;
115 %end;
116 %local fname2 libref2;
117 %let fname2=%mf_getuniquefileref();
118 %let libref2=%mf_getuniquelibref();
119 proc http method='GET' out=&fname2 &oauth_bearer
120 url=%unquote(%superq(href));
121 %if &grant_type=authorization_code %then %do;
122 headers "Authorization"="Bearer &&&access_token_var";
123 %end;
124 run;
125 libname &libref2 JSON fileref=&fname2;
126 data &outds;
127 length id $36 name $128 uri $64 type $32 description $256;
128 if _n_=1 then call missing (of _all_);
129 set &libref2..items;
130 run;
131 filename &fname2 clear;
132 libname &libref2 clear;
133%end;
134
135
136/* clear refs */
137filename &fname1 clear;
138libname &libref1 clear;
139
140%mend mv_getfoldermembers;