37 %macro mv_getjobcode(outref=0,outfile=0
39 ,contextName=SAS Job Execution compute context
40 ,access_token_var=ACCESS_TOKEN
41 ,grant_type=sas_services
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;
48 %
if &grant_type=sas_services %then %
do;
49 %let oauth_bearer=oauth_bearer=sas_services;
50 %let &access_token_var=;
52 %put &sysmacroname: grant_type=&grant_type;
53 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
54 and &grant_type ne sas_services
57 ,msg=%str(Invalid value
for grant_type: &grant_type)
59 %mp_abort(iftrue=(
"&path"=
"0")
61 ,msg=%str(Job Path not provided)
63 %mp_abort(iftrue=(
"&name"=
"0")
65 ,msg=%str(Job Name not provided)
67 %mp_abort(iftrue=(
"&outfile"=
"0" and
"&outref"=
"0")
69 ,msg=%str(Output destination (file or fileref) must be provided)
71 options noquotelenmax;
73 %let base_uri=%mf_getplatform(VIYARESTAPI);
76 %let foldermembers=&syslast;
77 %mv_getfoldermembers(root=&path
78 ,access_token_var=&access_token_var
79 ,grant_type=&grant_type
86 if name=
"&name" and uri=:
'/jobDefinitions/definitions'
87 then call symputx(
'joburi',uri);
89 %mp_abort(iftrue=(
"&joburi"=
"0")
91 ,msg=%str(Job &path/&name not found)
96 %let fname1=%mf_getuniquefileref();
97 proc http method=
'GET' out=&fname1 &oauth_bearer
98 url=
"&base_uri&joburi";
99 headers
"Accept"=
"application/vnd.sas.job.definition+json"
100 %
if &grant_type=authorization_code %then %
do;
101 "Authorization"=
"Bearer &&&access_token_var"
105 %
if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201 %then
107 data _null_;infile &fname1;input;putlog _infile_;run;
108 %mp_abort(mac=&sysmacroname
109 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
112 %local fname2 fname3 fpath1 fpath2 fpath3;
113 %let fname2=%mf_getuniquefileref();
114 %let fname3=%mf_getuniquefileref();
115 %let fpath1=%sysfunc(pathname(&fname1));
116 %let fpath2=%sysfunc(pathname(&fname2));
117 %let fpath3=%sysfunc(pathname(&fname2));
125 infile = io.open (sas.symget("fpath1"), "r")
126 outfile = io.open (sas.symget("fpath2"), "w")
128 local resp=json.decode(io.read())
129 local job=resp["code"]
138 %if &outref=0 %then %do;
139 file "&outfile" lrecl=32767;
148 filename &fname1 clear;
149 filename &fname2 clear;