BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
H-elmu-t
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
joeFurbee
Community Manager

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 XXXVI, Data Simulation
Wednesday, December 13, 2023, at 10 a.m. ET | #SASBowl

View solution in original post

8 REPLIES 8
alexal
SAS Employee

@H-elmu-t ,

 

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.

H-elmu-t
Obsidian | Level 7

 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

joeFurbee
Community Manager

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 XXXVI, Data Simulation
Wednesday, December 13, 2023, at 10 a.m. ET | #SASBowl

H-elmu-t
Obsidian | Level 7

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

pw182126
Fluorite | Level 6

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 🙂

AlanC
Barite | Level 11

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;

https://github.com/savian-net
yabwon
Meteorite | Level 14

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



GoncaloDias
Calcite | Level 5

This solved it. Thank you very much!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 4427 views
  • 1 like
  • 7 in conversation