30 %macro mv_deleteviyafolder(path=
31 ,access_token_var=ACCESS_TOKEN
32 ,grant_type=sas_services
35 %
if &grant_type=detect %then %
do;
36 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
37 %
else %let grant_type=sas_services;
39 %
if &grant_type=sas_services %then %
do;
40 %let oauth_bearer=oauth_bearer=sas_services;
41 %let &access_token_var=;
43 %put &sysmacroname: grant_type=&grant_type;
44 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
45 and &grant_type ne sas_services
48 ,msg=%str(Invalid value
for grant_type: &grant_type)
50 %mp_abort(iftrue=(%mf_isblank(&path)=1)
52 ,msg=%str(path value must be provided)
54 %mp_abort(iftrue=(%length(&path)=1)
56 ,msg=%str(path value must be provided)
59 options noquotelenmax;
61 %let base_uri=%mf_getplatform(VIYARESTAPI);
63 %put &sysmacroname: fetching details
for &path ;
65 %let fname1=%mf_getuniquefileref();
66 proc http method=
'GET' out=&fname1 &oauth_bearer
67 url=
"&base_uri/folders/folders/@item?path=&path";
68 %
if &grant_type=authorization_code %then %
do;
69 headers
"Authorization"=
"Bearer &&&access_token_var";
72 %
if &SYS_PROCHTTP_STATUS_CODE=404 %then %
do;
73 %put &sysmacroname: Folder &path NOT FOUND - nothing to
delete!;
76 %
else %
if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %
do;
78 %mp_abort(mac=&sysmacroname
79 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
83 %put &sysmacroname: grab the follow on link ;
85 %let libref1=%mf_getuniquelibref();
86 libname &libref1 JSON fileref=&fname1;
89 if rel=
'deleteRecursively' then
90 call symputx(
'href',quote(
"&base_uri"!!trim(href)),
'l');
91 else if rel=
'members' then
92 call symputx(
'mref',quote(cats(
"&base_uri",href,
'?recursive=true')),
'l');
97 %let fname1a=%mf_getuniquefileref();
98 proc http method=
'GET' out=&fname1a &oauth_bearer
99 url=%unquote(%superq(mref));
100 %
if &grant_type=authorization_code %then %
do;
101 headers
"Authorization"=
"Bearer &&&access_token_var";
104 %put &=SYS_PROCHTTP_STATUS_CODE;
106 %let libref1a=%mf_getuniquelibref();
107 libname &libref1a JSON fileref=&fname1a;
110 set &libref1a..items_links;
111 if href=:
'/folders/folders' then
return;
112 if rel=
'deleteResource' then
113 call execute(
'proc http method="DELETE" url='!!quote(
"&base_uri"!!trim(href))
114 !!
'; headers "Authorization"="Bearer &&&access_token_var" '
115 !!
' "Accept"="*/*";run; /**/');
118 %put &sysmacroname: perform the
delete operation ;
120 %let fname2=%mf_getuniquefileref();
121 proc http method=
'DELETE' out=&fname2 &oauth_bearer
122 url=%unquote(%superq(href));
124 %
if &grant_type=authorization_code %then %
do;
125 "Authorization"=
"Bearer &&&access_token_var"
129 %
if &SYS_PROCHTTP_STATUS_CODE ne 204 %then %
do;
130 data _null_; infile &fname2; input; putlog _infile_;run;
131 %mp_abort(mac=&sysmacroname
132 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
135 %
else %put &sysmacroname: &path successfully deleted;
138 filename &fname1 clear;
139 filename &fname2 clear;
140 libname &libref1 clear;