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";
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

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";
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
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.
Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
valengvz
Fluorite | Level 6
Thank you so much, it works for now!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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