BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MattClarke
Fluorite | Level 6

First, I want to thank these SAS legends for their insight, innovation and customer service focus: Chris Hemedinger, Joseph Henry and Vince DelGobbo! As we all know, there are multiple ways to accomplish what we need in our SAS projects, so it is vital that we have experts like these to help us navigate options and make better choices!

 

I am using a series of traditional techniques to collect external REST API data from external vendors for Physician Vacation planning purposes. We build a set of dynamic web pages, with this data, using PROC Stream to wrap HTML code around the JSON data returned from our REST call. 

 

One particular vendor has enhanced its REST API call to require an Auth Token and we are in the process of updating that call structure. Using cURL commands from %sysexec macros has been working perfectly for this new API as follows:

 

MattClarke_0-1590600345906.png

 

The resulting xxx_auth_token.json file contains the API authorization token required for the next series of API end-point calls to collect various types of vacation data. 

 

We are now working to convert the code above for security reasons, among other necessary requirements, to PROC HTTP. However, I am unable to determine the proper sequence of PROC HTTP options required to pass the "--data-urlencode" options shown in the base cURL command structure. 

 

I have tried IN=, HEADERS and a few other macro variable methods to include those values in a URL encrypted body but I am consistently getting the following error in my output headers file:

 

{"Message":"email and password are required"}

 

So, bottom line, How do we encapsulate cURL options and parameters into proper PROC HTTP syntax?

 

Thanks very much! 

1 ACCEPTED SOLUTION

Accepted Solutions
JosephHenry
SAS Employee

Hey,

 

I hope you are doing well. It is unfortunate that we were unable to see each other at SGF this year, because I cover this in my paper from this year that I did not get to present https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2020/4426-2020.pdf.

 

If you are lucky enough to be using Viya 3.5 (or when SAS 9.4m7 comes out) you can easily do this with the code below:

 

%let email=joseph.henry@sas.com;
%let password=mypassword&$#;
%let url=https://api.qgenda.com/v2/login;

filename token "auth_token.json";

proc http
 url="&url."
 method=POST
 out = token
 IN = FORM ("email"="&email."
            "password"="&password.");
run;

If using an earlier version of SAS, you can accomplish the same thing, but you have to run a DATA step to URL encode the parameters like this:

%let email=joseph.henry@sas.com;
%let password=mypassword;
%let url=https://api.qgenda.com/v2/login;


data _null_;
 email = urlencode("&email.");
 password = urlencode("&password.");

 call symputx("encoded_email",email,G);
 call symputx("encoded_password",password,G);
run;

filename token "auth_token.json";

proc http
 url="&url."
 method="POST"
 out = token
 in = "email=&encoded_email.%nrstr(&password)=&encoded_password.";
run;

Hope this helps!! 

View solution in original post

3 REPLIES 3
JosephHenry
SAS Employee

Hey,

 

I hope you are doing well. It is unfortunate that we were unable to see each other at SGF this year, because I cover this in my paper from this year that I did not get to present https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2020/4426-2020.pdf.

 

If you are lucky enough to be using Viya 3.5 (or when SAS 9.4m7 comes out) you can easily do this with the code below:

 

%let email=joseph.henry@sas.com;
%let password=mypassword&$#;
%let url=https://api.qgenda.com/v2/login;

filename token "auth_token.json";

proc http
 url="&url."
 method=POST
 out = token
 IN = FORM ("email"="&email."
            "password"="&password.");
run;

If using an earlier version of SAS, you can accomplish the same thing, but you have to run a DATA step to URL encode the parameters like this:

%let email=joseph.henry@sas.com;
%let password=mypassword;
%let url=https://api.qgenda.com/v2/login;


data _null_;
 email = urlencode("&email.");
 password = urlencode("&password.");

 call symputx("encoded_email",email,G);
 call symputx("encoded_password",password,G);
run;

filename token "auth_token.json";

proc http
 url="&url."
 method="POST"
 out = token
 in = "email=&encoded_email.%nrstr(&password)=&encoded_password.";
run;

Hope this helps!! 

MattClarke
Fluorite | Level 6

Hi Joseph!! Awesome as usual! 😎 Your solution for non-Viya "stragglers" like us - was perfect! And I appreciate it very much! 

 

In my multiple iterations of recent attempts, it turns out I was missing the symputx and passing the URL encrypted credentials! I was trying to pass the whole thing in a symputx macro variable which mangled the %nrstr for the &password value! 

 

Thank you again! You have saved my week! 😊

JosephHenry
SAS Employee

Glad I could help!

I am glad you posted the CUrl code, that makes it quite easy for me to convert to PROC HTTP.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1189 views
  • 4 likes
  • 2 in conversation