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

Hi there, I'm trying to translate this code into SAS code with PROC HTTP

 

curl --insecure -k  https://server/oauth/token -H "Accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=password&username=user&password=xxxx" -u client:clientsecret"

So far, I have this SAS code

 

proc http url="&server_host/&server_endpoint_token"
in=jsonin
webusername="client"
webpassword="clientsecret"
CT="Content-Type=application/x-www-form-urlencoded"
out=jsonout
headerout=headout;
debug level=3;
headers "Accept"="application/json" ;
run;

 The problem is that I have to accept the self-signed certificate but I don't know how to implement that in the PROC HTTP procedure.

 

Does someone know how to do that? 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

Some tweaks to the way you transcribed the cURL to PROC HTTP:

 

 

proc http url="&server_host/&server_endpoint_token"
    in="%nrstr(&grant_type)=password%nrstr(&username)=user"
    webusername="client"
    webpassword="clientsecret"
    CT="application/x-www-form-urlencoded"
    out=jsonout
    headerout=headout;
	debug level=3;
    headers "Accept"="application/json" ;
run;

 

 If you share more about which service you're using (if it's something common), we might have a better example.

 

the IN= takes what you specify in cURL -d option. The webusername/webpassword takes what you specify in the -u option. CT= is shorthand for "Content-Type" so no need to include the "Content-Type=" as part of the value.

 

The SSLPARMS statement can help specify behavior for verifying certificates. Adding the SSLREQCERT= value may help.

Something like:

 

sslparms "sslreqcert"="allow";
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

Some tweaks to the way you transcribed the cURL to PROC HTTP:

 

 

proc http url="&server_host/&server_endpoint_token"
    in="%nrstr(&grant_type)=password%nrstr(&username)=user"
    webusername="client"
    webpassword="clientsecret"
    CT="application/x-www-form-urlencoded"
    out=jsonout
    headerout=headout;
	debug level=3;
    headers "Accept"="application/json" ;
run;

 

 If you share more about which service you're using (if it's something common), we might have a better example.

 

the IN= takes what you specify in cURL -d option. The webusername/webpassword takes what you specify in the -u option. CT= is shorthand for "Content-Type" so no need to include the "Content-Type=" as part of the value.

 

The SSLPARMS statement can help specify behavior for verifying certificates. Adding the SSLREQCERT= value may help.

Something like:

 

sslparms "sslreqcert"="allow";
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
valengvz
Fluorite | Level 6

I'm using your code but it seems like there is a problem with the credentials, this is the way I created the jsonin file, I already correct the PROC HTTP statement as well

 

 

filename jsonin temp lrecl=32760;
filename jsonout temp lrecl=32760;
filename headout temp lrecl=32760;
%let string= 'grant_type=password&username=client&password=xxxx';

data _null_;
	call symputx('FLEN', length(&string));
run;

data _null_;
	file jsonin recfm=F lrecl=&FLEN;
	put &string;
run;


proc http url="&server_host/&server_endpoint_token"
    in=jsonin
    webusername="client"
    webpassword="cleintsecret"
    CT="application/x-www-form-urlencoded"
    out=jsonout
    headerout=headout;
	debug level=3;
    headers "Accept"="application/json" ;
run;

 

ChrisHemedinger
Community Manager
Why not skip creating the file and just put the literal value in the IN=, at least for now? Your value (which isn't JSON anyway) might have extra quotes from your %LET statement.
Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
valengvz
Fluorite | Level 6
Thank you so much, it works for now!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1271 views
  • 0 likes
  • 2 in conversation