36%macro mv_createfolder(path=
37 ,access_token_var=ACCESS_TOKEN
38 ,grant_type=sas_services
43%
if &mdebug=1 %then %
do;
44 %put &sysmacroname entry vars:;
51 msg=Cannot enter &sysmacroname with syscc=&syscc
54%
if %mfv_existfolder(&path)=1 %then %
do;
55 %&dbg.put &sysmacroname: &path already exists;
57 self_uri=
"%mfv_getpathuri(&path)";
63%mp_abort(iftrue=(&syscc ne 0),msg=syscc=&syscc when folder checking)
66%
if &grant_type=detect %then %
do;
67 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
68 %
else %let grant_type=sas_services;
70%
if &grant_type=sas_services %then %
do;
71 %let oauth_bearer=oauth_bearer=sas_services;
72 %let &access_token_var=;
75%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
76 and &grant_type ne sas_services
79 ,msg=%str(Invalid value
for grant_type: &grant_type)
82%mp_abort(iftrue=(%mf_isblank(&path)=1)
84 ,msg=%str(path value must be provided)
86%mp_abort(iftrue=(%length(&path)=1)
88 ,msg=%str(path value must be provided)
94%let subfolder_cnt=%sysfunc(countw(&path,/));
97%let base_uri=%mf_getplatform(VIYARESTAPI);
100%let href=
"&base_uri/folders/folders?parentFolderUri=/folders/folders/none";
102%local x newpath subfolder;
103%
do x=1 %to &subfolder_cnt;
104 %let subfolder=%scan(&path,&x,%str(/));
105 %let newpath=&newpath/&subfolder;
108 %let fname1=%mf_getuniquefileref();
110 %put &sysmacroname checking to see
if &newpath exists;
111 proc http method=
'GET' out=&fname1 &oauth_bearer
112 url=
"&base_uri/folders/folders/@item?path=&newpath";
113 %
if &grant_type=authorization_code %then %
do;
114 headers
"Authorization"=
"Bearer &&&access_token_var";
117 %
if &SYS_PROCHTTP_STATUS_CODE=401 %then %
do;
119 %put 401 thrown in &sysmacroname;
120 %put sleeping: %sysfunc(sleep(12,1)) secs - will try again;
121 proc http method='GET' out=&fname1 &oauth_bearer
122 url="&base_uri/folders/folders/@item?path=&newpath";
123 %if &grant_type=authorization_code %then %do;
124 headers "Authorization"="Bearer &&&access_token_var";
129 %let libref1=%mf_getuniquelibref();
130 libname &libref1 JSON fileref=&fname1;
133 &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 404
135 ,mac=mv_createfolder124
136 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
138 %if &mdebug=1 %then %do;
139 %put &sysmacroname following check to see if &newpath exists:;
147 %if &SYS_PROCHTTP_STATUS_CODE=200 %then %do;
148 %*put &sysmacroname &newpath exists so grab the follow on link ;
151 if rel='createChild' then
152 call symputx('href',quote(cats("&base_uri",href)),'l');
155 %else %if &SYS_PROCHTTP_STATUS_CODE=404 %then %do;
156 %put &sysmacroname &newpath not found - creating it now;
158 %let fname2=%mf_getuniquefileref();
163 ,quote(trim(symget('subfolder
')))
165 ,quote("&subfolder, created by &sysmacroname")
169 call symputx('json',json,'l');
172 proc http method='POST'
176 url=%unquote(%superq(href));
178 %if &grant_type=authorization_code %then %do;
179 "Authorization
"="Bearer &&&access_token_var
"
181 'Content-Type'='application/vnd.sas.content.folder+json'
182 'Accept'='application/vnd.sas.content.folder+json';
184 %if &SYS_PROCHTTP_STATUS_CODE ne 201 %then %do;
185 %put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
187 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
189 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
192 %let libref2=%mf_getuniquelibref();
193 libname &libref2 JSON fileref=&fname2;
194 %put &sysmacroname &newpath now created. Grabbing the follow on link ;
197 if rel='createChild' then do;
198 call symputx('href',quote(cats("&base_uri
",href)),'l');
201 if method='GET' and rel='self' then do;
208 libname &libref2 clear;
209 filename &fname2 clear;
211 filename &fname1 clear;
212 libname &libref1 clear;
215 iftrue=(&syscc ne 0),
216 msg=Cannot leave &sysmacroname with syscc=&syscc
218%mend mv_createfolder;