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 @sasjslint {"maxLineLength": 82}
35**/
36
37%macro mv_deletefoldermember(path=
38 ,name=
39 ,contenttype=
40 ,access_token_var=ACCESS_TOKEN
41 ,grant_type=sas_services
42 );
43%local oauth_bearer;
44%if &grant_type=detect %then %do;
45 %if %symexist(&access_token_var) %then %let grant_type=authorization_code;
46 %else %let grant_type=sas_services;
47%end;
48%if &grant_type=sas_services %then %do;
49 %let oauth_bearer=oauth_bearer=sas_services;
50 %let &access_token_var=;
51%end;
52
53%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
54 and &grant_type ne sas_services
55 )
56 ,mac=&sysmacroname
57 ,msg=%str(Invalid value for grant_type: &grant_type)
58)
59%mp_abort(iftrue=(%mf_isblank(&path)=1)
60 ,mac=&sysmacroname
61 ,msg=%str(path value must be provided)
62)
63%mp_abort(iftrue=(%mf_isblank(&name)=1)
64 ,mac=&sysmacroname
65 ,msg=%str(name value must be provided)
66)
67%mp_abort(iftrue=(%length(&path)=1)
68 ,mac=&sysmacroname
69 ,msg=%str(path value must be provided)
70)
71
72options noquotelenmax;
73
74%local base_uri; /* location of rest apis */
75%let base_uri=%mf_getplatform(VIYARESTAPI);
76
77%put &sysmacroname: fetching details for &path ;
78%local fname1;
79%let fname1=%mf_getuniquefileref();
80proc http method='GET' out=&fname1 &oauth_bearer
81 url="&base_uri/folders/folders/@item?path=&path";
82%if &grant_type=authorization_code %then %do;
83 headers "Authorization"="Bearer &&&access_token_var";
84%end;
85run;
86%if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;
87 %put &sysmacroname: Folder &path NOT FOUND - nothing to delete!;
88 %return;
89%end;
90%else %if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %do;
91 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
92 %mp_abort(mac=&sysmacroname
93 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
94 )
95%end;
96
97%put &sysmacroname: grab the follow on link ;
98%local libref1;
99%let libref1=%mf_getuniquelibref();
100libname &libref1 JSON fileref=&fname1;
101data _null_;
102 set &libref1..links;
103 if rel='members' then call symputx('mref',quote("&base_uri"!!trim(href)),'l');
104run;
105
106/* get the children */
107%local fname1a;
108%let fname1a=%mf_getuniquefileref();
109proc http method='GET' out=&fname1a &oauth_bearer
110 url=%unquote(%superq(mref));
111%if &grant_type=authorization_code %then %do;
112 headers "Authorization"="Bearer &&&access_token_var";
113%end;
114run;
115%if &SYS_PROCHTTP_STATUS_CODE ne 200 %then %do;
116 %put &=sysmacroname &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
117%end;
118%local libref1a;
119%let libref1a=%mf_getuniquelibref();
120libname &libref1a JSON fileref=&fname1a;
121%local uri found;
122%let found=0;
123/* %put Getting object uri from &libref1a..items; */
124data _null_;
125 length contenttype name $1000;
126 set &libref1a..items;
127 if contenttype="&contenttype" and upcase(name)="%upcase(&name)" then do;
128 call symputx('uri',uri,'l');
129 call symputx('found',1,'l');
130 end;
131run;
132%if &found=0 %then %do;
133 %put NOTE:;%put NOTE- &sysmacroname: &path/&name NOT FOUND;%put NOTE- ;
134 %return;
135%end;
136proc http method="DELETE" url="&base_uri&uri" &oauth_bearer;
137 headers
138%if &grant_type=authorization_code %then %do;
139 "Authorization"="Bearer &&&access_token_var"
140%end;
141 "Accept"="*/*";/**/
142run;
143%if &SYS_PROCHTTP_STATUS_CODE ne 204 %then %do;
144 data _null_; infile &fname2; input; putlog _infile_;run;
145 %mp_abort(mac=&sysmacroname
146 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
147 )
148%end;
149%else %put &sysmacroname: &path/&name(&contenttype) successfully deleted;
150
151/* clear refs */
152filename &fname1 clear;
153libname &libref1 clear;
154filename &fname1a clear;
155libname &libref1a clear;
156
157%mend mv_deletefoldermember;