29 %macro mv_createfolder(path=
30 ,access_token_var=ACCESS_TOKEN
31 ,grant_type=sas_services
34 %
if &grant_type=detect %then %
do;
35 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
36 %
else %let grant_type=sas_services;
38 %
if &grant_type=sas_services %then %
do;
39 %let oauth_bearer=oauth_bearer=sas_services;
40 %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)
51 %mp_abort(iftrue=(%mf_isblank(&path)=1)
53 ,msg=%str(path value must be provided)
55 %mp_abort(iftrue=(%length(&path)=1)
57 ,msg=%str(path value must be provided)
60 options noquotelenmax;
63 %let subfolder_cnt=%sysfunc(countw(&path,/));
66 %let href=
"/folders/folders?parentFolderUri=/folders/folders/none";
69 %let base_uri=%mf_getplatform(VIYARESTAPI);
71 %local x newpath subfolder;
72 %
do x=1 %to &subfolder_cnt;
73 %let subfolder=%scan(&path,&x,%str(/));
74 %let newpath=&newpath/&subfolder;
77 %let fname1=%mf_getuniquefileref();
79 %put &sysmacroname checking to see
if &newpath exists;
80 proc http method=
'GET' out=&fname1 &oauth_bearer
81 url=
"&base_uri/folders/folders/@item?path=&newpath";
82 %
if &grant_type=authorization_code %then %
do;
83 headers
"Authorization"=
"Bearer &&&access_token_var";
87 %let libref1=%mf_getuniquelibref();
88 libname &libref1 JSON fileref=&fname1;
89 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 404)
91 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
93 %
if &SYS_PROCHTTP_STATUS_CODE=200 %then %
do;
94 %put &sysmacroname &newpath exists so grab the follow on link ;
97 if rel=
'createChild' then
98 call symputx(
'href',quote(
"&base_uri"!!trim(href)),
'l');
101 %
else %
if &SYS_PROCHTTP_STATUS_CODE=404 %then %
do;
102 %put &sysmacroname &newpath not found - creating it now;
104 %let fname2=%mf_getuniquefileref();
109 ,quote(trim(symget(
'subfolder')))
111 ,quote(
"&subfolder, created by &sysmacroname")
115 call symputx(
'json',json,
'l');
118 proc http method=
'POST'
122 url=%unquote(%superq(href));
124 %
if &grant_type=authorization_code %then %
do;
125 "Authorization"=
"Bearer &&&access_token_var"
127 'Content-Type'=
'application/vnd.sas.content.folder+json'
128 'Accept'=
'application/vnd.sas.content.folder+json';
130 %put &=SYS_PROCHTTP_STATUS_CODE;
131 %put &=SYS_PROCHTTP_STATUS_PHRASE;
132 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 201)
134 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
137 %let libref2=%mf_getuniquelibref();
138 libname &libref2 JSON fileref=&fname2;
139 %put &sysmacroname &newpath now created. Grabbing the follow on link ;
142 if rel=
'createChild' then
143 call symputx(
'href',quote(trim(href)),
'l');
146 libname &libref2 clear;
147 filename &fname2 clear;
149 filename &fname1 clear;
150 libname &libref1 clear;