Help using Base SAS procedures

Requesting Guidance on making a PROC HTTP call by passing bearer token

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

Requesting Guidance on making a PROC HTTP call by passing bearer token

[ Edited ]

All, 
     I am new to SAS and have been trying to learn and appreciate the help of anyone who can guide me on this issue. I have an internal API which I have successfully accessed using R, I am trying to now learn how to the same using PROC HTTP. My R code that works successfully is provided below, I am also attaching my attempt of the SAS code:

 

RawResponse1 <- GET(RequestURL1, add_headers('Authorization' = paste0('Bearer ', AccessToken)))

    In the above code, RequestURL1 and AccessToken are custom built. My attempt and rebuilding this in SAS is shown below: 

       filename ProjResp "/ProjApiResponse.txt"; * edited the filepath ;

	Proc HTTP
	    URL = URLDes
            Method ="get" 
            Out = ProjResp 
            ct = "Authorization" = "Bearer &AccessToken"; 
	Run;

        * URLDes is the custom URL equivalent to RequestURL1 in the previous case ;

 


Accepted Solutions
Solution
a week ago
Community Manager
Posts: 3,432

Re: Requesting Guidance on making a PROC HTTP call by passing bearer token

Posted in reply to UdayGuntupalli

And then did you SYMPUT the value into a macro variable?  Your computed name in the DATA step won't be in scope by the time you get to the PROC HTTP step -- you have to store it in a macro variable.  Try this:

 

Data _null_; 
 URLDes = &URLToUse || "/" || &ProjectID || "/" || "Prediction" || "/" || &PredictionID;
 call symputx('URLDes',URLDes); 
;
Run; 
proc http
 method="GET"
 url = "&URLDes."
 out=ProjResp;
 headers
   "Authorization"="Bearer &AccessToken.";
run;

View solution in original post


All Replies
Community Manager
Posts: 3,432

Re: Requesting Guidance on making a PROC HTTP call by passing bearer token

Posted in reply to UdayGuntupalli

You want the HEADERS statement in PROC HTTP.

 

I have a complex example here.

 

Your code would look like:

 

	Proc HTTP
	    URL = URLDes
            Method ="get" 
            Out = ProjResp ;
            headers "Authorization" = "Bearer &AccessToken"; 
	Run;
Contributor
Posts: 36

Re: Requesting Guidance on making a PROC HTTP call by passing bearer token

Posted in reply to ChrisHemedinger

@ChrisHemedinger

          Thanks a lot for your response. I edited the code per your suggestion, please see below : 

 

Proc HTTP
        URL = URLDes
        Method ="get" 
        Out = ProjResp ;
        headers "Authorization" = "Bearer &AccessToken"; 
Run;

          I receive the following errors and I don't understand what the errors mean. Could you kindly offer any further guidance ? 

 

image.png

Community Manager
Posts: 3,432

Re: Requesting Guidance on making a PROC HTTP call by passing bearer token

Posted in reply to UdayGuntupalli

What's the value of URLDes?  This should be a quoted string with with URL of the web service you're calling.

 

And I assume you have a macro variable with that's assigned with the value of you access token, eg:

 

%let AccessToken=123454678992ehgue;
Community Manager
Posts: 3,432

Re: Requesting Guidance on making a PROC HTTP call by passing bearer token

Posted in reply to ChrisHemedinger
Contributor
Posts: 36

Re: Requesting Guidance on making a PROC HTTP call by passing bearer token

[ Edited ]
Posted in reply to ChrisHemedinger
Data _null_; 
		URLDes = &URLToUse || "/" || &ProjectID || "/" || "Prediction" || "/" || &PredictionID; 
		put URLDes; 
		Test = vtype(URLDes); 
		put Test= ;
		%put &AccessToken;
Run; 

 From the steps shown above, URLDes is a valid  hyperlink, it is saved as a character. So, wondering what the issue is 

tI1p-YLmpMDkNfHs6e1NASTCNqzBxitqruK1KqEezOckgUDDX8An_AT8iEKgt9qpXuhNlvpJWOMshvVJm7ZqC3_pneDRZkXisEvHvytYmwWMAOqduAC6fdP6zUZlfETlxNib
zUabPhtGRie-c7RW1WAkg3lOviPDyUZQ31UjC9ES6vgojzjHmV6I75ngIdUtD22W6EGoR9enXPdW6H-BCzT-DqDZKBsQULrHauwm08IGP__tVwmzP85cEDf96h_eTS1jK4d1
Ydy67TT5T3FOADP31h5oCUIRZtUkytwL3lT_JxFPRN_tJpwXxa_xhwqJRisMaA
 
Test=C
Solution
a week ago
Community Manager
Posts: 3,432

Re: Requesting Guidance on making a PROC HTTP call by passing bearer token

Posted in reply to UdayGuntupalli

And then did you SYMPUT the value into a macro variable?  Your computed name in the DATA step won't be in scope by the time you get to the PROC HTTP step -- you have to store it in a macro variable.  Try this:

 

Data _null_; 
 URLDes = &URLToUse || "/" || &ProjectID || "/" || "Prediction" || "/" || &PredictionID;
 call symputx('URLDes',URLDes); 
;
Run; 
proc http
 method="GET"
 url = "&URLDes."
 out=ProjResp;
 headers
   "Authorization"="Bearer &AccessToken.";
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 156 views
  • 2 likes
  • 2 in conversation