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.
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;
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 */
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.
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.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.