Authorization
This page will guide you through how to get the OAuth 2.0 access token
Your security is our number 1 priority. You can follow OAuth 2.0 client credential flow.
In short, once you have registered, you should receive a client ID and a client secret. Once you have those, you can get an access token from GET <<api_base_path>>/oauth/token
. You can access the remaining APIs using this access token.
The access token will expire according to the API responses. If it is expired, simply call GET /oauth/token
again to refresh the token.
Replace <<client_id>>
& <<client_secret>>
by your client ID and a client secret in the code snippet below:
require "uri"
require "net/http"
require "json"
url = URI("https://<<api_base_path>>/oauth/token")
https = Net::HTTP.new(url.host, url.port);
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
payload = {
client_id: "<<client_id>>",
client_secret: "<<client_secret>>",
grant_type: "client_credentials"
}
request.body = JSON.generate(payload)
response = https.request(request)
response_payload = JSON.parse(response.read_body)
puts "access_token #{response_payload['access_token']}"
puts "expired in #{response_payload['expires_in']} seconds"
<?php
$curl = curl_init();
$payload = [
"client_id" => "<<client_id>>",
"client_secret" => "<<client_secret>>",
"grant_type" => "client_credentials",
];
curl_setopt_array($curl, [
CURLOPT_URL => "https://<<api_base_path>>/oauth/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
curl_close($curl);
$responsePayload = json_decode($response, true);
echo "access_token {$response_payload['access_token']}" . PHP_EOL;
echo "expired in {$response_payload['expires_in']} seconds" . PHP_EOL;
curl --location --request POST 'https://<<api_base_path>>/oauth/token' \
--header 'Content-Type: application/json' \
--data-raw '{
"client_id": "<<client_id>>",
"client_secret": "<<client_secret>>",
"grant_type": "client_credentials"
}'
Updated over 1 year ago