Ottenere il Token di accesso


Per ottenere il tuo token di accesso hai bisogno delle chiavi API (ClientID | ClientSecret), nome utente e password fornite da Keliweb al momento della registrazione al servizio. Questa guida ti fornisce tutti i dettagli per ottenere, aggiornare e revocare il tuo token di accesso. I token di accesso hanno una durata di 1 ora (3600s). I token di aggiornamento scadono in 10 giorni.

Endpoint

Method URI
POST https://fatture.keliweb.it/oauth/token

Request Parameters

Parameter Type Description Required
grant_type string default value: password Yes
client_id string The client ID provided to access APIs Yes
client_secret string The client secret key provided to access APIs Yes
username string The client email address Yes
password string The client password Yes

Response Parameters

Parameter Type Description
token_type string default value: Bearer
expires_in integer The token lifetime (in seconds)
access_token string The access token
refresh_token string The refresh token

Example Request (BASH Curl)

curl --location --request POST 'https://fatture.keliweb.it/oauth/token' \
--form 'grant_type="password"' \
--form 'username="test@example.com"' \
--form 'password="xxxxxxx"' \
--form 'client_id="4a6af340-2672-11ec-8114-3ba47a898cf0"' \
--form 'client_secret="UhoPgAS8rnAm57J8dLXWqKDTFnwjzS30pLzE572Z"'

Example Request (PHP Curl)

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://fatture.keliweb.it/oauth/token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => false,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>
    http_build_query(
            array(
                'grant_type'    => 'password',
                'client_id'     => 'ea9ea94e-a0c2-4b87-9834-26b218ed26a0',
                'client_secret' => 'MoQSElJG5MoLkVhRJCJ7jdQZVwfbrtwKKepwOsXO',
                'username'      => 'test@example.com',
                'password'      => 'xxxxxxx',
            )
        ),
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/x-www-form-urlencoded",
    "X-Requested-With: XMLHttpRequest"
  ),
));

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

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Example Request (jQuery AJAX)

var form = new FormData();

form.append("grant_type", "password");
form.append("client_id", "ea9ea94e-a0c2-4b87-9834-26b218ed26a0");
form.append("client_secret", "MoQSElJG5MoLkVhRJCJ7jdQZVwfbrtwKKepwOsXO");
form.append("username", "test@example.com");
form.append("password", "xxxxxxx");

var settings = {
    async: true,
    crossDomain: true,
    url: "https://fatture.keliweb.it/oauth/token",
    method: "POST",
    headers: {
        "cache-control": "no-cache"
    },
    processData: false,
    contentType: false,
    mimeType: "multipart/form-data",
    data: form
};

$.ajax(settings).done(function(response) {
    console.log(response);
});

Example Request (Python - Requests)

import requests

url = "https://fatture.keliweb.it/oauth/token"

payload={'grant_type': 'password',
'username': 'test@example.com',
'password': 'xxxxxxx',
'client_id': '4a6af340-2672-11ec-8114-3ba47a898cf0',
'client_secret': 'UhoPgAS8rnAm57J8dLXWqKDTFnwjzS30pLzE572Z'}
files=[

]
headers = {}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

Example Response (JSON payload)

{
    "token_type": "Bearer",
    "expires_in": 3600,
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImYyYjBjOWNkODFiYzRmODMwOGZlNjZkZj",
    "refresh_token": "def50200cb918cb70defe79d45f1f2193c4c0a959fd78a5c3123e5d3f33f3b8af6b1080f6c745"
}