Create Authentication Token
Creates the new authentication token for the specified user.
Request
HTTP Request
Permissions
Path parameters
Parameter | Type | Description |
---|---|---|
id | Stringrequired |
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 a string with an authentication token.
Warning
Authentication token in the response body is surrounded by quotation marks ("
). Some requests may require you to remove them.
Example
Request
Here is how you can create a new authentication token for a user with ID user_id
:
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();
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:
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();