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";

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";
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.
valengvz
Fluorite | Level 6
Thank you so much, it works for now!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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