Hi,
I am trying to execute a SAS Viya job twice with a Rest API calls using PROC HTTP.
Therefore I first get an access token...
filename resp temp; proc http url="https://mysasserver.net:443/SASLogon/oauth/token" method='post' in="grant_type=password%nrstr(&username=)&USERNAME.%nrstr(&password=)&PASSWORD." username="&CLIENT_ID." password="&CLIENT_SECRET." out=resp auth_basic verbose; debug level=3; run; libname tokens json "%sysfunc(pathname(resp))"; %global ACCESS_TOKEN; proc sql noprint; select access_token into:ACCESS_TOKEN, from tokens.root; quit;
...and then perform my first call:
filename out1 temp;
proc http
url='https://mysasserer.net/SASJobExecution/?_program=/Public/code/model/score&rating=%7B"ID1":"''B1484000''","ID2":32000%7D'
out=out1
OAUTH_BEARER="&ACCESS_TOKEN."
method="POST";
headers "Content-Type"="application/xml";
debug level=2;
run;
data _null_;
infile out1;
input;
put _INFILE_;
run;
That works perfectly fine - results are as expected.
But when I then try to execute the 2nd call...
filename out2 temp;
proc http
url='https://mysasserer.net/SASJobExecution/?_program=/Public/code/model/score&rating=%7B"ID1":"''A2484001''","ID2":32001%7D'
out=out2
OAUTH_BEARER="&ACCESS_TOKEN."
method="POST";
headers "Content-Type"="application/xml";
debug level=2;
run;
data _null_;
infile out2;
input;
put _INFILE_;
run;
...then I receive the message "Forbidden":
{"timestamp":"2020-04-15T07:19:58.426Z","status":403,"error":"Forbidden","message":"Forbidden","path":"/SASJobExecution/"}
What do I do wrong here?
Why is my PROC HTTP call only works once?
Maybe someone can help me with this?
Thanks & best regards,
Helmut
Hi @H-elmu-t.
I also ran this by a couple of colleagues. They were unable to reproduce, but had this feedback:
Try running with GET vs POST. Using GET with a single call should be sufficient in this instance. You also most likely don't need the headers in your calls.
They'd also like to know the jobexec app version and SAS Viya release. Thanks!
Join us for SAS Community Trivia
SAS Bowl XLVII, SAS Visual Text Analytics
Wednesday, December 18, 2024, at 10:30 a.m. ET | #SASBowl
Did you register your client as described in https://developer.sas.com/apis/rest/#introduction? Also, I would like to see a response to your first request where you are trying to get a token.
Dear @alexal ,
Yes, I registered as described in the documentation.
The response of the first request is the following:
{"access_token":"eyJhbGciOiJSUzI1NiIsIm....","token_type":"bearer","id_token":"eyJhbGciOiJSUzI1NiIsImprdSI6I.....","expires_in":43199,"scope":"ATRRNEU_ORG .... openid ...","jti":"3ee0c3981e4946278f55043187cbfdf5"}
Please note - I shortened the tokens and the scope list in the above response.
Nevertheless - when I use GET instead of POST the problem does not occur anymore anyway.
Thanks & best regards,
Helmut
Hi @H-elmu-t.
I also ran this by a couple of colleagues. They were unable to reproduce, but had this feedback:
Try running with GET vs POST. Using GET with a single call should be sufficient in this instance. You also most likely don't need the headers in your calls.
They'd also like to know the jobexec app version and SAS Viya release. Thanks!
Join us for SAS Community Trivia
SAS Bowl XLVII, SAS Visual Text Analytics
Wednesday, December 18, 2024, at 10:30 a.m. ET | #SASBowl
Hi @joeFurbee ,
Good news:
Using GET instead of POST solved the problem - thanks a lot!
My Viya version is V.03.05M0P111119 (taken from PROC SETINIT output).
But I don't know where to check the jobexec app version?
Thanks & best regards,
Helmut
Hi! We have the same issue.
Unfortunately we need to use POST request in order to transfer big JSON as input parameter for the job. The URL limit is about 2000 character. We need to send mote than this and that why we need to use POST request.
In the jobexecug 2.0 documentation I can see that it must be possible:
"jobexec.method HTTP method used when this request was made (for example, GET, POST, or PUT)."
Hope there is a solution for this 🙂
Here is a sample multi request with proc http. You need SAS 9.4M4 or higher:
/*===================================================
| USAGE: OPERATIONAL CURL
| -----------------------------------------------------
|
| curl --location --request POST 'http://localhost:9003/Email/SendEmailAsync?toAddresses=alan.churchill%40savian.net&subject=PostMan' \
| --header 'accept: text/plain' \
| --header 'Content-Type: multipart/form-data' \
| --form 'files=@"/E:/temp/Secured/work/message.html"' \
| --form 'files=@"/E:/temp/Secured/work/QA.xlsx"'
*====================================================*/
filename xcl "E:\temp\Secured\HCAHPS\work\Analysis.xlsx";
filename input "E:\temp\Secured\HCAHPS\work\message.html";
filename debug "e:\temp\SasHttp.txt";
proc http
url="http://daasserver01:9003/Email/SendEmailAsync"
query = ("toAddresses"="alan.churchill@savian.net"
"subject"="SAS Email")
headerout=debug
method="POST"
in = multi FORM ( "message.html" = input header="Content-Type: text/html",
Analysis.xlsx" = xcl header="Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
);
DEBUG LEVEL=3;
run;
Hey SAS-C!
I know the thread is already solved but I faced the same problem (with POST too) and the solution was to add CLEAR_CACHE option (specifies to clear both the shared connection and cookie caches before the HTTP request is executed)
SAS Help Center: Syntax: PROC HTTP PROC HTTP Statement
All the best
Bart
This solved it. Thank you very much!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.