48%macro mv_getfoldermembers(root=/
49 ,access_token_var=ACCESS_TOKEN
50 ,grant_type=sas_services
54%
if &grant_type=detect %then %
do;
55 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
56 %
else %let grant_type=sas_services;
58%
if &grant_type=sas_services %then %
do;
59 %let oauth_bearer=oauth_bearer=sas_services;
60 %let &access_token_var=;
63%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
64 and &grant_type ne sas_services
67 ,msg=%str(Invalid value
for grant_type: &grant_type)
70%
if %mf_isblank(&root)=1 %then %let root=/;
76%let fname1=%mf_getuniquefileref();
77%let libref1=%mf_getuniquelibref();
80%let base_uri=%mf_getplatform(VIYARESTAPI);
82%
if "&root"=
"/" %then %
do;
84 proc http method=
'GET' out=&fname1 &oauth_bearer
85 url=
"&base_uri/folders/rootFolders?limit=1000";
86 %
if &grant_type=authorization_code %then %
do;
87 headers
"Authorization"=
"Bearer &&&access_token_var";
90 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
92 ,msg=%str(Root folders: &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
94 libname &libref1 JSON fileref=&fname1;
97 %
if %sysfunc(exist(&libref1..items))=1 %then %
do;
104 length ordinal_root 8 ordinal_items 8
105 creationTimeStamp $32 modifiedTimeStamp $32
106 createdBy $64 modifiedBy $64
107 id $36 uri $512 added $32 type $32
108 name $256 description $256;
112 call missing(of _all_);
115 if missing(name) and missing(uri) then delete;
119 %put NOTE: &sysmacroname - no root folders found;
121 length ordinal_root 8 ordinal_items 8
122 creationTimeStamp $32 modifiedTimeStamp $32
123 createdBy $64 modifiedBy $64
124 id $36 uri $512 added $32 type $32
125 name $256 description $256;
126 call missing(of _all_);
133 proc http method=
'GET' out=&fname1 &oauth_bearer
134 url=
"&base_uri/folders/folders/@item?path=&root";
135 %
if &grant_type=authorization_code %then %
do;
136 headers
"Authorization"=
"Bearer &&&access_token_var";
139 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
141 ,msg=%str(Folder lookup: &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
144 libname &libref1 JSON fileref=&fname1;
150 %
if %sysfunc(exist(&libref1..links))=1 %then %
do;
152 length rel href $512;
153 call missing(rel,href);
155 if rel=
'members' then
do;
156 url=cats(
"'",
"&base_uri",href,
"?limit=10000'");
157 call symputx(
'href',url,
'l');
158 call symputx(
'cnt',1,
'l');
162 %
if &cnt=0 %then %
do;
163 %put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
167 length ordinal_root 8 ordinal_items 8
168 creationTimeStamp $32 modifiedTimeStamp $32
169 createdBy $64 modifiedBy $64
170 id $36 uri $512 added $32 type $32
171 name $256 description $256;
172 call missing(of _all_);
175 filename &fname1 clear;
176 libname &libref1 clear;
179 %local fname2 libref2;
180 %let fname2=%mf_getuniquefileref();
181 %let libref2=%mf_getuniquelibref();
182 proc http method=
'GET' out=&fname2 &oauth_bearer
183 url=%unquote(%superq(href));
184 %
if &grant_type=authorization_code %then %
do;
185 headers
"Authorization"=
"Bearer &&&access_token_var";
188 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
190 ,msg=%str(Folder members: &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
192 libname &libref2 JSON fileref=&fname2;
195 %
if %sysfunc(exist(&libref2..items))=1 %then %
do;
197 length ordinal_root 8 ordinal_items 8
198 creationTimeStamp $32 modifiedTimeStamp $32
199 createdBy $64 modifiedBy $64
200 id $36 uri $512 added $32 type $32
201 name $256 description $256;
205 call missing(of _all_);
208 if missing(name) and missing(uri) then delete;
212 %put NOTE: &sysmacroname - &root is empty;
214 length ordinal_root 8 ordinal_items 8
215 creationTimeStamp $32 modifiedTimeStamp $32
216 createdBy $64 modifiedBy $64
217 id $36 uri $512 added $32 type $32
218 name $256 description $256;
219 call missing(of _all_);
223 filename &fname2 clear;
224 libname &libref2 clear;
229filename &fname1 clear;
230libname &libref1 clear;
232%mend mv_getfoldermembers;