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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Chuck_IV4
Obsidian | Level 7

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.

View solution in original post

3 REPLIES 3
Chuck_IV4
Obsidian | Level 7

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.

ChrisHemedinger
Community Manager

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.

SAS Innovate 2026: Register now! April 27-30 in Grapevine TX -- it's the premier conference for SAS users!
Jejeremy87
Calcite | Level 5

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.

 

 

 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 4678 views
  • 1 like
  • 3 in conversation