94%macro mv_getjobresult(uri=0
95 ,access_token_var=ACCESS_TOKEN
96 ,grant_type=sas_services
103%
if &mdebug=1 %then %
do;
104 %put &sysmacroname entry vars:;
110%
if &grant_type=detect %then %
do;
111 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
112 %
else %let grant_type=sas_services;
114%
if &grant_type=sas_services %then %
do;
115 %let oauth_bearer=oauth_bearer=sas_services;
116 %let &access_token_var=;
119%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
120 and &grant_type ne sas_services
123 ,msg=%str(Invalid value
for grant_type: &grant_type)
131 if length(uri)<12 then
do;
132 call symputx(
'errflg',1);
133 call symputx(
'errmsg',
"URI is invalid (too short) - '&uri'",
'l');
135 if scan(uri,-1)=
'state' or scan(uri,1) ne 'jobExecution' then do;
136 call symputx('errflg',1);
137 call symputx('errmsg',
138 "URI should be in format /jobExecution/jobs/$$$$UUID$$$$"
139 !!" but is actually like: &uri",'l');
143%mp_abort(iftrue=(&errflg=1)
148%if &outref ne 0 and %mf_existfileref(&outref) ne 1 %then %do;
149 filename &outref temp;
152options noquotelenmax;
154%let base_uri=%mf_getplatform(VIYARESTAPI);
158%let fname1=%mf_getuniquefileref();
159proc http method='GET' out=&fname1 &oauth_bearer
161 headers "Accept"="application/json"
162 %if &grant_type=authorization_code %then %do;
163 "Authorization"="Bearer &&&access_token_var"
167%if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201 %then
169 data _null_;infile &fname1;input;putlog _infile_;run;
170 %mp_abort(mac=&sysmacroname
171 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
174%if &mdebug=1 %then %do;
176 infile &fname1 lrecl=32767;
184%let lib1=%mf_getuniquelibref();
185libname &lib1 JSON fileref=&fname1;
188 call symputx('resuri',_&result,'l');
189 &dbg putlog "&sysmacroname results: " (_all_)(=);
191%if "&resuri"="." %then %do;
198 %put &sysmacroname: _&result not found in job results -;
199 %put &sysmacroname: use mv_getjoblog to fetch the job log instead;
200 %if &outref ne 0 %then %do;
203 put "&sysmacroname: no &_result result available for job &uri";
206 %if &outlib ne 0 %then %do;
208 %let fname3=%mf_getuniquefileref();
213 libname &outlib JSON fileref=&fname3;
215 %if &mdebug=0 %then %do;
216 filename &fname1 clear;
221%mp_abort(iftrue=("&resuri"=".")
223 ,msg=%str(Variable _&result did not exist in the response json)
228%let fname2=%mf_getuniquefileref();
229proc http method='GET
' out=&fname2 &oauth_bearer
230 url="&base_uri&resuri/content?limit=10000";
231 headers "Accept"="application/json"
232 %if &grant_type=authorization_code %then %do;
233 "Authorization"="Bearer &&&access_token_var"
237%if &mdebug=1 %then %do;
238 /* send one char at a time as the json can be very wide */
240 infile &fname2 recfm=n;
242 putlog char $char1. @;
246%if &outref ne 0 %then %do;
247 filename &outref temp;
248 %mp_binarycopy(inref=&fname2,outref=&outref)
250%if &outlib ne 0 %then %do;
251 libname &outlib JSON fileref=&fname2;
254%if &mdebug=0 %then %do;
255 filename &fname1 clear;
256 filename &fname2 clear;
260 %put &sysmacroname exit vars:;
264%mend mv_getjobresult;