Project

General

Profile

API - Token generation

URL: /account/token/
Method: GET

A user token is required for most of the API sections, it identifies a guest user or a logged-in customer. The same token is used when a guest logs in, the login data is attached to the already generated token.

$api_id = 1;
$api_key = 'testpass';
$hostname = 'https://example.com'; // no trailing slash

# fetch data
$url = '/account/token/';
$post_data = array();
$extra_headers = array(
    'X-API-ID: ' . $api_id,
    'X-API-Hash: ' . md5($api_key . $url . http_build_query($post_data))
);

$json = sendRequest($hostname . $url, $post_data, $extra_headers);

if (!empty($json)) {
    $response = json_decode($json);

    if (empty($response->has_error) && !empty($response->results->token)) {
        $user_token = $response->results->token; // you should store this in the DB on your side, do not generate for every request
    }
}

Succes message :

{
    has_error: false,
    messages: [ ],
    results: {
        token: "xxx" 
    }
}

Tokens expire after 6 months since last use. In this case, the following error will be issued:

{
    has_error: true,
    messages: [
        "User token is invalid or expired" 
    ],
    results: [ ]
}

Go to top