To get your API access details, use the Cedato Dashboard. Under Network Settings->Platform API Key generate, you will be able to generate or regenerate your client ID and client secret string.
The client application uses the access token it received in every subsequent request to the Platform API WS in a special header:
Authorization: bearer DaRfdfaR...MzYjw
Requesting a token:
POST /api/token
Headers:
accept: application/json
api-version: 1
authorization: Basic
content-type: application/x-www-form-urlencoded
Request body:
grant_type=client_credentials
cURL example:
curl --request POST
--url https://api.cedato.com/api/token
--header 'accept: application/json'
--header 'api-version: 1'
--header 'authorization: Basic '
--header 'content-type: application/x-www-form-urlencoded'
Create Oauth Token Script
define(
'CEDATO_API_ENDPOINT_URL'
,
'https://api.cedato.com/api/'
);
define(
'CEDATO_API_ID_CLIENT'
,
'123456789'
);
define(
'CEDATO_API_ID_SECRET'
,
'123456789'
);
$res
= curl_init();
curl_setopt_array(
$res
,
array
(
CURLOPT_URL => CEDATO_API_ENDPOINT_URL.
'token'
,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(
array
(
'grant_type'
=>
'client_credentials'
)),
CURLOPT_HTTPHEADER =>
array
(
'accept: application/json'
,
'api-version: 1'
,
'authorization: Basic
'.base64_encode(CEDATO_API_ID_CLIENT.'
:'.CEDATO_API_ID_SECRET),
'content-type: application/x-www-form-urlencoded'
),
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE
));
$response
= curl_exec(
$res
);
curl_close(
$res
);
var_dump(
$response
);
?>
Receiving a token response
The API server sends back a response similar to this:
{
"access_token": "DaRfdfaR...MzYjw",
"token_type": "bearer",
"expires_in": 3600, //In seconds
}
Valid API requests must include the sent token as part of the authorization header
Here you have an example for obtaining access tokem written in Python:
import requests
import base64
import json
import csv
#importing relevant packages
def GetToken(): # a Function responsible for getting a Dynamic API key
url = "https://api.cedato.com/api/token"
payload = "grant_type=client_credentials"
Access_key = 'XXXXXXXXXXX' # API user name
secret_key = 'XXXXXXXXXXX' # API password
enc_auth = base64.b64encode(
'{}:{}'.format(Access_key, secret_key).encode('utf-8')) # API key (username+password as base64)
headers = {
'authorization': "Basic XXXXXXXXX",
'accept': "application/json",
'api-version': "1",
'content-type': "application/x-www-form-urlencoded",
'cache-control': "no-cache",
}
response = requests.request("POST", url, data=payload, headers=headers)
content = response.content.decode('utf-8')
d = json.loads(content)
token = d['data']['access_token']
bearer = 'Bearer ' + token
print(bearer)
return bearer #returnning the Key
##################################################################################### Calling API
def call_api(response,is_json):
if response.status_code == 200: # API request was approved
content = response.content # content of the report
content = content.decode('utf-8') # now you have a string and not bytes
else:
print(response.status_code)
content = response.content # content of the report
content = content.decode('utf-8') # now you have a string and not bytes
if is_json:
return json.loads(content)
print(content)
return content