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 @sasjslint {"maxLineLength": 230}
41**/
42
43%macro mv_getfoldermembers(root=/
44 ,access_token_var=ACCESS_TOKEN
45 ,grant_type=sas_services
46 ,outds=mv_getfolders
47 );
48%local oauth_bearer;
49%if &grant_type=detect %then %do;
50 %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
51 %else %let grant_type=sas_services;
52%end;
53%if &grant_type=sas_services %then %do;
54 %let oauth_bearer=oauth_bearer=sas_services;
55 %let &access_token_var=;
56%end;
57
58%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
59 and &grant_type ne sas_services
60 )
61 ,mac=&sysmacroname
62 ,msg=%str(Invalid value for grant_type: &grant_type)
63)
64
65%if %mf_isblank(&root)=1 %then %let root=/;
66
67options noquotelenmax;
68
69/* request the client details */
70%local fname1 libref1;
71%let fname1=%mf_getuniquefileref();
72%let libref1=%mf_getuniquelibref();
73
74%local base_uri; /* location of rest apis */
75%let base_uri=%mf_getplatform(VIYARESTAPI);
76
77%if "&root"="/" %then %do;
78 /* if root just list root folders */
79 proc http method='GET' out=&fname1 &oauth_bearer
80 url="&base_uri/folders/rootFolders?limit=1000";
81 %if &grant_type=authorization_code %then %do;
82 headers "Authorization"="Bearer &&&access_token_var";
83 %end;
84 run;
85 libname &libref1 JSON fileref=&fname1;
86 data &outds;
87 set &libref1..items;
88 run;
89%end;
90%else %do;
91 /* first get parent folder id */
92 proc http method='GET' out=&fname1 &oauth_bearer
93 url="&base_uri/folders/folders/@item?path=&root";
94 %if &grant_type=authorization_code %then %do;
95 headers "Authorization"="Bearer &&&access_token_var";
96 %end;
97 run;
98 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
99 libname &libref1 JSON fileref=&fname1;
100 /* now get the followon link to list members */
101 %local href cnt;
102 %let cnt=0;
103 data _null_;
104 length rel href $512;
105 call missing(rel,href);
106 set &libref1..links;
107 if rel='members' then do;
108 url=cats("'","&base_uri",href,"?limit=10000'");
109 call symputx('href',url,'l');
110 call symputx('cnt',1,'l');
111 end;
112 run;
113 %if &cnt=0 %then %do;
114 %put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
115 %return;
116 %end;
117 %local fname2 libref2;
118 %let fname2=%mf_getuniquefileref();
119 %let libref2=%mf_getuniquelibref();
120 proc http method='GET' out=&fname2 &oauth_bearer
121 url=%unquote(%superq(href));
122 %if &grant_type=authorization_code %then %do;
123 headers "Authorization"="Bearer &&&access_token_var";
124 %end;
125 run;
126 libname &libref2 JSON fileref=&fname2;
127 data &outds;
128 length id $36 name $128 uri $64 type $32 description $256;
129 if _n_=1 then call missing (of _all_);
130 set &libref2..items;
131 run;
132 filename &fname2 clear;
133 libname &libref2 clear;
134%end;
135
136
137/* clear refs */
138filename &fname1 clear;
139libname &libref1 clear;
140
141%mend mv_getfoldermembers;