Create Session ID

POST /node/api/users/session

Creates a new session ID that should be used for authentication in the subsequent requests.

Request parameters

Body parameters

Parameter

Type

Description

login

string

required

User's login.

password

string

required

User's password.

Response description

...

Examples

Creating a new session ID

Bash
JavaScript
NodeJS
Python
Bash
login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/users/session
curl -X POST $url \
-H "Content-Type: application/json" \
--data '{"login": "'$login'", "password": "'$password'"}' \
--cookie-jar cookies.txt
JavaScript
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/users/session";
let headers = new Headers();
headers.append("Content-Type", "application/json");
let data = JSON.stringify({
"login": login,
"password": password
});
let requestOptions = {
method: "POST",
headers: headers,
body: data
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log("error", error));
NodeJS
const http = require("http");
let login = <...>
let password = <...>
let saymonHostname = <...>
let path = "/node/api/users/session";
let options = {
"method": "POST",
"hostname": saymonHostname,
"headers": {
"Content-Type": "application/json"
},
"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);
});
});
let data = JSON.stringify({
login: login,
password: password
});
req.write(data);
req.end();
Python
import requests
login = <...>
password = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/users/session"
body = {"login": login, "password": password}
response = requests.request("POST", url, json=body)
session_id = response.text
print(session_id)

Using the created session ID for authentication

After a new session ID is created, you need to provide it in the Cookie header in the subsequent requests. The examples below show how this can be done for the Get Current User method:

Bash
JavaScript
NodeJS
Python
Bash
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/users/current
curl -X GET $url --cookie cookies.txt
JavaScript
let sessionId = <...>
let saymonHostname = <...>
let path = "/node/api/users/current";
let headers = new Headers();
headers.append("Cookie", "sid=" + sessionId);
let requestOptions = {
method: "GET",
headers: headers
};
fetch(saymonHostname + path, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log("error", error));
NodeJS
const http = require("http");
let sessionId = <...>
let saymonHostname = <...>
let path = "/node/api/users/current";
let options = {
"method": "GET",
"hostname": saymonHostname,
"headers": {
"Cookie": "sid=" + sessionId
},
"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();
Python
import requests
session_id = <...>
saymon_hostname = <...>
url = "https://" + saymon_hostname + "/node/api/users/current"
headers = {"Cookie": "sid=" + session_id}
response = requests.request("GET", url, headers=headers)
print(response.text)