Skip to content

Create Authentication Token

Creates a new authentication token.

Request

HTTP Request

POST /node/api/users/:id/auth-token

Permissions

manage-users

Path parameters

Parameter Type Description
id String
required
The ID of a user for which an authentication token should be created.

Request body

The request body is empty.

Response

The response body contains the string with an authentication token.

Example

Request

Here is how you can create a new authentication token for a user with ID user_id:

login=<...>
password=<...>
user_id=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/users/$user_id/auth-token

curl -X POST $url -u $login:$password
let login = <...>
let password = <...>
let userId = <...>
let saymonHostname = <...>
let path = "/node/api/users/" + userId + "/auth-token";
let auth = "Basic " + btoa(login + ":" + password);

let headers = new Headers();
headers.append("Authorization", auth);

let requestOptions = {
    method: "POST",
    headers: headers
};

fetch(saymonHostname + path, requestOptions)
    .then(response => response.text())
    .then(result => console.log(result))
    .catch(error => console.log("error", error));
const http = require("http");

let login = <...>
let password = <...>
let userId = <...>
let saymonHostname = <...>
let path = "/node/api/users/" + userId + "/auth-token";
let auth = "Basic " + Buffer.from(login + ":" + password).toString("base64");

let options = {
    "method": "POST",
    "hostname": saymonHostname,
    "headers": {
        Authorization: auth
    },
    "path": path
};

let req = http.request(options, function (res) {
    let chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function (chunk) {
        let body = Buffer.concat(chunks);
        console.log(body.toString());
    });

    res.on("error", function (error) {
        console.error(error);
    });
});

req.end();
import requests

login = <...>
password = <...>
user_id = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/users/" + \
    user_id + "/auth-token"

response = requests.request("POST", url, auth=(login, password))
print(response.text)

After the token is created, the user needs to provide it as a query parameter to authenticate in the subsequent requests. The examples below show how to do it for the Get Current User method:

saymon_hostname=<...>
api_token=<...>
url=https://$saymon_hostname/node/api/users/current

curl -X GET $url?api-token=$api_token
let authToken = <...>
let saymonHostname = <...>
let path = "/node/api/users/current?api-token=" + authToken;

let requestOptions = {
    method: "GET"
};

fetch(saymonHostname + path, requestOptions)
    .then(response => response.text())
    .then(result => console.log(result))
    .catch(error => console.log("error", error));
const http = require("http");

let authToken = <...>
let saymonHostname = <...>
let path = "/node/api/users/current?api-token=" + authToken;

let options = {
    "method": "GET",
    "hostname": saymonHostname,
    "path": path
};

let req = http.request(options, function (res) {
    let chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function (chunk) {
        let body = Buffer.concat(chunks);
        console.log(body.toString());
    });

    res.on("error", function (error) {
        console.error(error);
    });
});

req.end();
import requests

api_token = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/users/current"
params = {"api-token": api_token}

response = requests.request("GET", url, params=params)
print(response.text)

Response

"6c41afda-0f18-4613-983f-3e01d83c6aaa"

See Also