Hello Everyone,
I am struggling to get Proc HTTP to return an Access Token from a company called Listrak, uing their REST API. I AM able to get it from Postman, using their instructions, but I cannot seem to translate that into something that works with Proc HTTP.
This is the Postman HTTP code that works(client_id/secret x'd out for security)...
POST /OAuth2/Token HTTP/1.1
Host: auth.listrak.com
Cache-Control: no-cache
Postman-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&client_id=xxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxx
The SAS code I have tried is this but it always returns a "Bad Request" from the headerout and {"error":"Invalid Grant Type"} error from the resptkn file...
filename resptkn TEMP;
filename headers TEMP;
%let client_credentials = xxxxxxxxxxxxxxxxxxxxxx;
%let client secret = xxxxxxxxxxxxxxxxxxxxxxxxxx;
%let oauth2_token = https://auth.listrak.com/OAuth2/Token
proc http
method="POST"
url="&oauth2_token.?grant_type=client_credentials%str(&)client_id=&client_id%str(&)client_secret=&client_secret"
ct="application/x-www-form-urlencoded"
headerout=headers
out=resptkn
HEADEROUT_OVERWRITE;
run;
I "think" the issue is based on the fact that with Postman, I had to put the credentials and grant type in the BODY portion and not the header portion. While I know about the Headers option in Proc HTTP, I don't know how to put anything into a BODY portiong with proc HTTP.
Once I have a token, I am able to connect to their REST
Any help would be much appreciated.
Thank You
I FINALLY got it. WOW. Here is the code I used to get it to generate the code...
proc http
method="POST"
url="https://auth.listrak.com/OAuth2/Token"
ct="application/x-www-form-urlencoded"
in='grant_type=client_credentials&client_id=xxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxx'
headerout=headers
out=resptkn
HEADEROUT_OVERWRITE;
run;
I guess the key was to not only send the grant type via the IN= option, but also the credentials. That seemed to be my hangup. I kept trying to send them as part of the initial URL.
I FINALLY got it. WOW. Here is the code I used to get it to generate the code...
proc http
method="POST"
url="https://auth.listrak.com/OAuth2/Token"
ct="application/x-www-form-urlencoded"
in='grant_type=client_credentials&client_id=xxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxx'
headerout=headers
out=resptkn
HEADEROUT_OVERWRITE;
run;
I guess the key was to not only send the grant type via the IN= option, but also the credentials. That seemed to be my hangup. I kept trying to send them as part of the initial URL.
Great! You can also use DATA step to write body content to a SAS fileref, then specify the fileref on the in= option in PROC HTTP. Useful when the body content is more data driven.
Hi Guys.
Thanks for all informations, i really appreciate it.
Indeed, i am in the same position.
I need to connect with a proc http to return Access Token via REST API...
With Potstman, i get the acess token without problem :
Method : POST
URL : "https://services-xxxxxxxxxxxxxx/token"
Passing information in the body :
client_id=XXXX;
client_secret = XXXX;
Grant_type = client_credentials
Headers : Content-Type = application/x-www-form-urlencoded
Authorisation : Type = OAUTH 2.0 Request Header.
In SAS, i met some difficulties. I tried to use the code mentioned above.
Unfornutally, i have a bad request with a invalid_client resp.
filename resptkn temp;
filename headers temp;
proc http
method="POST"
url="https://services-xxxxxxxxxxxxxx/token"
ct="application/x-www-form-urlencoded"
in='client_id=XXXX&client_secret=XXXX&grant_type=client_credentials'
headerout=headers
out=resptkn
HEADEROUT_OVERWRITE
;
run;
>>> {"error":"invalid_client"}
I used this proc to connect SAS with GA api or salesforce and i didnt' met issu..
Do you have an idea ?
Thanks in advance for your help.
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.