Obtention d'un token



Authentification

URL
https://accountsandbox.hubintent.com/oauth/token
verbe HTTP
POST

Headers

Clé
Valeur
Content-Type
application/x-www-form-urlencoded

Body (x-ww-form-urlencoded)

grant_type
client_credentials
client_id
le CLIENT_ID de votre compte développeur
client_secret
le CLIENT_SECRET de votre compte développeur

Exemple de requête d'obtention de token

Un exemple d'implémentation dans différents langages est disponible ci-dessous:
cURL :
curl \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=CLIENT_ID" \
-d "client_secret=CLIENT_SECRET" \
"https://accountsandbox.hubintent.com/oauth/token"
PHP :
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://accountsandbox.hubintent.com/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
NodeJS :
var qs = require("querystring");
var http = require("https");

var options = {
"method": "POST",
"hostname": "accountsandbox.hubintent.com",
"port": null,
"path": "/oauth/token",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"cache-control": "no-cache"
}
};

var req = http.request(options, function (res) {
var chunks = [];

res.on("data", function (chunk) {
chunks.push(chunk);
});

res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});

req.write(qs.stringify({ grant_type: 'client_credentials',
client_id: 'CLIENT_ID',
client_secret: 'CLIENT_SECRET' }));
req.end();
Python :
import http.client

conn = http.client.HTTPSConnection("accountsandbox.hubintent.com")

payload = "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET"

headers = {
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache"
}

conn.request("POST", "/oauth/token", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
Java :
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET");
Request request = new Request.Builder()
.url("https://accountsandbox.hubintent.com/oauth/token")
.post(body)
.addHeader("content-type", "application/x-www-form-urlencoded")
.addHeader("cache-control", "no-cache")
.build();

Response response = client.newCall(request).execute();
RestSharpe :
var client = new RestClient("https://accountsandbox.hubintent.com/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

En réponse, vous recevrez un access_token :
JSON :
{
"token_type":"bearer",
"access_token":"bc378d50dca644816b777afd26d21e7260bb8296",
"expires_in":3600
}
Cet access_token devra être utilisé pour chaque requête vers l'API intent, sous forme de header :
Authorization : Bearer access_token