Skip to main content
Skip table of contents

Create an аccess token tо API: Auth.CreateApiToken

The method and parameters

The method is used to create an access token to JSON-RPC API. Every API method, except for this method, must include a request authorization token either in the Token parameter or in the Authorization request header.

This method must be called from a local address (localhost) - otherwise, an error will always be returned.

string Auth.CreateApiToken(unsigned ttl)

Parameters

unsigned ttl REQUIRED – the duration of the generated token, in seconds. If 0 is specified, the duration is unlimited.

POST /api/

JSON-RPC
JSON
{
    "jsonrpc": "2.0",
    "method": "Auth.CreateApiToken",
    "params": {
        "ttl": 0
    },
    "id": 1
}
cURL
BASH
curl -k --request POST \
	--url 'https://your-domain/api/' \
	--header 'Content-Length: 114' \
	--header 'Content-Type: application/json' \
	--header 'Accept: application/json' \
	--header 'Authorization: Bearer <api-authorization-token>' \
	--header 'Content-Length: <Data length>' \
	--data '{
    "jsonrpc": "2.0",
    "method": "Auth.CreateApiToken",
    "params": {
        "ttl": 0
    },
    "id": 1
}'
PHP
PHP
$data = array (
  'jsonrpc' => '2.0',
  'method' => 'Auth.CreateApiToken',
  'params' => 
  array (
    'ttl' => 0,
  ),
  'id' => 1,
);
$context = stream_context_create([
	'ssl'=>['verify_peer' => false],
	'http' => [
		'method' => 'POST',
		'header' => "Content-Type: application/json\r
Accept: application/json\r
Authorization: Bearer <api-authorization-token>\r
Content-Length: <Data lenth>",
		'content'=>json_encode($data)
	]
]);
$result = file_get_contents('https://your-domain/api/', false, $context);

200 OK

An OAuth token

JSON
"<api-auth-token>"

400 Bad Request

JSON-RPC error

JSON
{
    "error": {
        "code": -32601,
        "message": "Method not found"
    }
}

500 Internal Server Error

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.