BookmarkSubscribeRSS Feed
Jejeremy87
Calcite | Level 5
 

 

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.

 

1 REPLY 1
RichardDeVen
Barite | Level 11

You would have to check with the service host to understand what the response

 

 {"error":"invalid_client"}

actually means.

 

 

One guess is the client in the message is related to the agent of the client application instead of an invalid client_id parameter.

 

If you examine the default headers sent by PROC HTTP you will find the user agent is

 

HTTP_USER_AGENT = SAS/9

Compare to a standard web browser that might represent itself as follows 

 

 

HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36 Edg/81.0.416.53

 

 

Try sending a different User-Agent in your PROC HTTP step:

 

* create text file that contains one line per request header in the format key:value;
filename hdrs_in temp; data _null_; file hdrs_in; input; put _infile_; datalines4; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36 Edg/81.0.416.53 ;;;;

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'

HEADERIN=HDRS_IN /* force a different User-Agent */

headerout=headers
out=resptkn
HEADEROUT_OVERWRITE
;
run;

 

 

Tip: I used a simple PHP script on my web host to show me the inbound headers and parameters:

<?php
   header('Content-type: text/plain');

   echo "HEADERS:\n";
   ksort($_SERVER);
   foreach($_SERVER as $key=>$value) if (substr($key,0,4)=="HTTP") { echo $key, ' = ', $value, "\n"; }

   echo "\n_GET:\n";
   ksort($_GET);
   foreach($_GET as $key=>$value) { echo $key, ' = ', $value, "\n"; }

   echo "\n_POST:\n";
   ksort($_POST);
   foreach($_POST as $key=>$value) { echo $key, ' => ', $value, "\n"; }
?>

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 1007 views
  • 0 likes
  • 2 in conversation