36%macro mv_deleteviyafolder(path=
37 ,access_token_var=ACCESS_TOKEN
38 ,grant_type=sas_services
42%
if &grant_type=detect %then %
do;
43 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
44 %
else %let grant_type=sas_services;
46%
if &grant_type=sas_services %then %
do;
47 %let oauth_bearer=oauth_bearer=sas_services;
48 %let &access_token_var=;
51%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
52 and &grant_type ne sas_services
55 ,msg=%str(Invalid value
for grant_type: &grant_type)
57%mp_abort(iftrue=(%mf_isblank(&path)=1)
59 ,msg=%str(path value must be provided)
61%mp_abort(iftrue=(%length(&path)=1)
63 ,msg=%str(path value must be provided)
68%let base_uri=%mf_getplatform(VIYARESTAPI);
70%put &sysmacroname: fetching details
for &path ;
72%let fname1=%mf_getuniquefileref();
73proc http method=
'GET' out=&fname1 &oauth_bearer
74 url=
"&base_uri/folders/folders/@item?path=&path";
75 %
if &grant_type=authorization_code %then %
do;
76 headers
"Authorization"=
"Bearer &&&access_token_var";
79%
if &SYS_PROCHTTP_STATUS_CODE=404 %then %
do;
80 %put &sysmacroname: Folder &path NOT FOUND - nothing to delete!;
83%
else %
if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %
do;
85 %mp_abort(mac=&sysmacroname
86 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
90%put &sysmacroname: grab the follow on link ;
92%let libref1=%mf_getuniquelibref();
93libname &libref1 JSON fileref=&fname1;
96 if rel=
'deleteRecursively' then
97 call symputx(
'href',quote(
"&base_uri"!!trim(href)),
'l');
98 else if rel=
'members' then
99 call symputx(
'mref',quote(cats(
"&base_uri",href,
'?recursive=true')),
'l');
104%let fname1a=%mf_getuniquefileref();
105proc http method=
'GET' out=&fname1a &oauth_bearer
106 url=%unquote(%superq(mref));
107%
if &grant_type=authorization_code %then %
do;
108 headers
"Authorization"=
"Bearer &&&access_token_var";
111%put &=SYS_PROCHTTP_STATUS_CODE;
113%let libref1a=%mf_getuniquelibref();
114libname &libref1a JSON fileref=&fname1a;
116%
if %mf_existds(&libref1a..items_links) %then %
do;
118 set &libref1a..items_links;
119 if href=:
'/folders/folders' then
return;
120 if rel=
'deleteResource' then
121 call execute(
'proc http method="DELETE" url='
122 !!quote(
"&base_uri"!!trim(href))
123 !!
'; headers "Authorization"="Bearer &&&access_token_var" '
124 !!
' "Accept"="*/*";run; /**/');
128%put &sysmacroname: perform the delete operation ;
130%let fname2=%mf_getuniquefileref();
131proc http method=
'DELETE' out=&fname2 &oauth_bearer
132 url=%unquote(%superq(href));
134 %
if &grant_type=authorization_code %then %
do;
135 "Authorization"=
"Bearer &&&access_token_var"
139%
if &SYS_PROCHTTP_STATUS_CODE ne 204 %then %
do;
140 data _null_; infile &fname2; input; putlog _infile_;run;
141 %mp_abort(mac=&sysmacroname
142 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
145%
else %put &sysmacroname: &path successfully deleted;
147%
if &mdebug=0 %then %
do;
149 filename &fname1 clear;
150 filename &fname2 clear;
151 libname &libref1 clear;
154%mend mv_deleteviyafolder;