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";
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

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";
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
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.
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
valengvz
Fluorite | Level 6
Thank you so much, it works for now!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2420 views
  • 0 likes
  • 2 in conversation