Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mv_deletefoldermember.sas
Go to the documentation of this file.
1/**
2 @file mv_deletefoldermember.sas
3 @brief Deletes an item in a Viya folder
4 @details If not executed in Studio 5+ will expect oauth token in a global
5 macro variable (default ACCESS_TOKEN).
6
7 filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
8 %inc mc;
9
10 %mv_createwebservice(path=/Public/test, name=blah)
11 %mv_deletejes(path=/Public/test, name=blah)
12
13
14 @param [in] path= ()
15 The full path of the folder containing the item to be deleted
16 @param [in] name= The name of the item to be deleted
17 @param [in] contenttype= The contenttype of the item, eg: file, jobDefinition
18 @param [in] access_token_var= (ACCESS_TOKEN)
19 The global macro variable to contain the access token
20 @param [in] grant_type= (sas_services)
21 valid values are "password" or "authorization_code" (unquoted).
22
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**/
35
36%macro mv_deletefoldermember(path=
37 ,name=
38 ,contenttype=
39 ,access_token_var=ACCESS_TOKEN
40 ,grant_type=sas_services
41 );
42%local oauth_bearer;
43%if &grant_type=detect %then %do;
44 %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
45 %else %let grant_type=sas_services;
46%end;
47%if &grant_type=sas_services %then %do;
48 %let oauth_bearer=oauth_bearer=sas_services;
49 %let &access_token_var=;
50%end;
51
52%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
53 and &grant_type ne sas_services
54 )
55 ,mac=&sysmacroname
56 ,msg=%str(Invalid value for grant_type: &grant_type)
57)
58%mp_abort(iftrue=(%mf_isblank(&path)=1)
59 ,mac=&sysmacroname
60 ,msg=%str(path value must be provided)
61)
62%mp_abort(iftrue=(%mf_isblank(&name)=1)
63 ,mac=&sysmacroname
64 ,msg=%str(name value must be provided)
65)
66%mp_abort(iftrue=(%length(&path)=1)
67 ,mac=&sysmacroname
68 ,msg=%str(path value must be provided)
69)
70
71options noquotelenmax;
72
73%local base_uri; /* location of rest apis */
74%let base_uri=%mf_getplatform(VIYARESTAPI);
75
76%put &sysmacroname: fetching details for &path ;
77%local fname1;
78%let fname1=%mf_getuniquefileref();
79proc http method='GET' out=&fname1 &oauth_bearer
80 url="&base_uri/folders/folders/@item?path=&path";
81%if &grant_type=authorization_code %then %do;
82 headers "Authorization"="Bearer &&&access_token_var";
83%end;
84run;
85%if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;
86 %put &sysmacroname: Folder &path NOT FOUND - nothing to delete!;
87 %return;
88%end;
89%else %if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %do;
90 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
91 %mp_abort(mac=&sysmacroname
92 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
93 )
94%end;
95
96%put &sysmacroname: grab the follow on link ;
97%local libref1;
98%let libref1=%mf_getuniquelibref();
99libname &libref1 JSON fileref=&fname1;
100data _null_;
101 set &libref1..links;
102 if rel='members' then call symputx('mref',quote("&base_uri"!!trim(href)),'l');
103run;
104
105/* get the children */
106%local fname1a;
107%let fname1a=%mf_getuniquefileref();
108proc http method='GET' out=&fname1a &oauth_bearer
109 url=%unquote(%superq(mref));
110%if &grant_type=authorization_code %then %do;
111 headers "Authorization"="Bearer &&&access_token_var";
112%end;
113run;
114%put &=SYS_PROCHTTP_STATUS_CODE;
115%local libref1a;
116%let libref1a=%mf_getuniquelibref();
117libname &libref1a JSON fileref=&fname1a;
118%local uri found;
119%let found=0;
120%put Getting object uri from &libref1a..items;
121data _null_;
122 length contenttype name $1000;
123 set &libref1a..items;
124 if contenttype="&contenttype" and upcase(name)="%upcase(&name)" then do;
125 call symputx('uri',uri,'l');
126 call symputx('found',1,'l');
127 end;
128run;
129%if &found=0 %then %do;
130 %put NOTE:;%put NOTE- &sysmacroname: &path/&name NOT FOUND;%put NOTE- ;
131 %return;
132%end;
133proc http method="DELETE" url="&base_uri&uri" &oauth_bearer;
134 headers
135%if &grant_type=authorization_code %then %do;
136 "Authorization"="Bearer &&&access_token_var"
137%end;
138 "Accept"="*/*";/**/
139run;
140%if &SYS_PROCHTTP_STATUS_CODE ne 204 %then %do;
141 data _null_; infile &fname2; input; putlog _infile_;run;
142 %mp_abort(mac=&sysmacroname
143 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
144 )
145%end;
146%else %put &sysmacroname: &path/&name(&contenttype) successfully deleted;
147
148/* clear refs */
149filename &fname1 clear;
150libname &libref1 clear;
151filename &fname1a clear;
152libname &libref1a clear;
153
154%mend mv_deletefoldermember;