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

Hello, 

 

can someone please help me convert the following (working) cURL command into the PROC HTTP equivalent?

 

curl -d '' -X POST 'https://api.bcda.cms.gov/auth/token' \
	--user 3841c594-a8c0-41e5-98cc-38bb45360d3c:f9780d323588f1cdfc3e63e95a8cbdcdd47602ff48a537b51dc5d7834bf466416a716bd4508e904a \
	-H "accept: application/json"

The parameters under --user are clientid:client secret key

The response which is expected for this request is :

{
"access_token": "eyJhbGciOiJSUzUxMiIsInR5c...",
"token_type":"bearer"
}

 

Any help is appreciated.

Thanks. 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

I think in cURL the --user option has the form "user:password" where the colon separates the user ID from the password. Would you try something like this?  Also, the -d option sets the content-type to application/x-www-form-urlencoded. You're not sending any content but I figured I'd set the content type in this call.

 

filename resp temp;
proc http
 url="https://api.bcda.cms.gov/auth/token"
 webusername="3841c594-a8c0-41e5-98cc-38bb45360d3c"
 webpassword="f9780d323588f1cdfc3e63e95a8cbdcdd47602ff48a537b51dc5d7834bf466416a716bd4508e904a"
 out=resp
 ct="application/x-www-form-urlencoded"
 method="POST";
 debug level=2;
headers "Accept"="application/json";
run;

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

View solution in original post

6 REPLIES 6
ChrisHemedinger
Community Manager

See this blog post: How to translate your cURL command to PROC HTTP.

 

It looks like you might end up with something like:

 

filename resp temp;
proc http
 url="https://api.bcda.cms.gov/auth/token"
 webuserid="3841c594-a8c0-41e5-98cc-38bb45360d3c:f9780d323588f1cdfc3e63e95a8cbdcdd47602ff48a537b51dc5d7834bf466416a716bd4508e904a"
 out=resp
 method="POST";
headers "Accept"="application/json";
run;

libname auth JSON fileref=resp;
/* use DATA step to get data from AUTH, the JSON response */
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Anmolkhandelwal
Obsidian | Level 7

I tried using the above code, gave me syntax error as below,

27         proc http
28          url="https://api.bcda.cms.gov/auth/token"
29          webuserid="c0a02574-6432-4e65-b8da-cb6f264b4544:c04473622271dd3ffa53ab0c85ed006fa6c0fb59b6d8e3409bd411e396599f7451cd53ae
            _________
            22
            76
29       ! f1b370a4"
ERROR 22-322: Syntax error, expecting one of the following: ;, AUTH_ANY, AUTH_BASIC, AUTH_NEGOTIATE, AUTH_NONE, AUTH_NTLM, 
              CLEAR_CACHE, CLEAR_CONN_CACHE, CLEAR_COOKIES, CT, EXPECT_100_CONTINUE, FOLLOWLOC, HEADERIN, HEADEROUT, 
              HEADEROUT_OVERWRITE, HTTP_TOKENAUTH, IN, METHOD, NOFOLLOW, NOFOLLOWLOC, NO_CONN_CACHE, NO_COOKIES, OUT, PROXYHOST, 
              PROXYPASSWORD, PROXYPORT, PROXYUSERNAME, PROXY_AUTH_BASIC, PROXY_AUTH_NEGOTIATE, PROXY_AUTH_NONE, PROXY_AUTH_NTLM, 
              URL, VERBOSE, WEBAUTHDOMAIN, WEBPASSWORD, WEBUSERNAME.  
ERROR 76-322: Syntax error, statement will be ignored.






Then i changed the webuserid to webusername and webpassword, Got the below error.

26         filename resp temp;
27         proc http
28          url="https://api.bcda.cms.gov/auth/token"
29          webusername="c0a02574-6432-4e65-b8da-cb6f264b4544"
30         	WEBPASSWORD = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
31          out=resp
32          method="POST";
33         headers "Accept"="application/json";
34         run;

ERROR: OpenSSL error 336032824 (0x14077438) occurred in SSL_connect/accept at line 5388, the error message is "error:14077438:SSL 
       routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error".
ERROR: Secure communications error status 807ff008 description "OpenSSL error 336032824 (0x14077438) occurred in SSL_connect/accept 
       at line 5388, the error message is "error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error"."
ERROR: Encryption run-time execution error
ERROR: Call to tcpSockContinueSSL failed.

Don't have much idea about such error.

 

ChrisHemedinger
Community Manager

My mistake - the proper syntax is webusername=.

 

filename resp temp;
proc http
 url="https://api.bcda.cms.gov/auth/token"
 webusername="3841c594-a8c0-41e5-98cc-38bb45360d3c:f9780d323588f1cdfc3e63e95a8cbdcdd47602ff48a537b51dc5d7834bf466416a716bd4508e904a"
 out=resp
 method="POST";
 debug level=2;
headers "Accept"="application/json";
run;

libname auth JSON fileref=resp;
data _null_;
 rc=jsonpp('resp','log');
run;

 According to the API doc they don't want a separate password -- it's all part of the user= value. 

 

The TLS error might be something else though. Make sure you can use PROC HTTP with SSL (certificates need to be in place). Here's how to test.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Anmolkhandelwal
Obsidian | Level 7
Well we tried the test, it ran through successfully.
however, when we ran the above code, this gave us "Access denied" as the api response and 403 Forbidden as the status code.
Just some additional info, we do have the access for the URL's and right credentials, as we were able to submit successful requests using postman and python.
Any suggestions on if we are missing something while sending the credentials to get a token using above code.
Thanks.
ChrisHemedinger
Community Manager

I think in cURL the --user option has the form "user:password" where the colon separates the user ID from the password. Would you try something like this?  Also, the -d option sets the content-type to application/x-www-form-urlencoded. You're not sending any content but I figured I'd set the content type in this call.

 

filename resp temp;
proc http
 url="https://api.bcda.cms.gov/auth/token"
 webusername="3841c594-a8c0-41e5-98cc-38bb45360d3c"
 webpassword="f9780d323588f1cdfc3e63e95a8cbdcdd47602ff48a537b51dc5d7834bf466416a716bd4508e904a"
 out=resp
 ct="application/x-www-form-urlencoded"
 method="POST";
 debug level=2;
headers "Accept"="application/json";
run;

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
Anmolkhandelwal
Obsidian | Level 7
We added options like :set=SSL_USE_SNI="1" set=SSL_SNI_HOSTNAME="URL"; to resolve the SSL issue we had.
The above code worked to get the response from the URL.

Thanks for your help 🙂

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1356 views
  • 1 like
  • 2 in conversation