Skip to content

Create Session ID

Creates a new Session, which is later used to authenticate other API requests.

This method returns a newly-created session ID. The Session ID is also included in the response's Set-Cookie header.

Request

HTTP Request

POST /node/api/users/session

Path parameters

No parameters required.

Body parameters

You can create new session using either a login and password, an authentication token, or an external authentication service (such as Keycloak).

Login/Email and password

Parameter Type Description
login String
required
User's login or email.
password String
required
User's password.

Authentication token

Parameter Type Description
auth-token String Authentication token.

External authentication service

Parameter Type Description
auth-service String Name of an authentication service. SAYMON currently supports only keycloak.
auth-service-params Object Authentication parameters.
auth-service-params.token Object Service's authentication token.

Request body

You can create new session using either a login and password, an authentication token, or an external authentication service (such as Keycloak).

Login/Email and password

If the user's email is set, they can use it to create session ID, instead of their login.

{
    "login": "user.name",
    "password": "P665bPVi"
}
{
    "login": "user.email@example.com",
    "password": "P665bPVi"
}

Authentication token

{
    "auth-token": <...>
}

External authentication service

Keycloak
{
    "auth-service": "keycloak",
    "auth-service-params": {
        "token": "..."
    }
}

Response

Response body contains a string with the session ID:

"a5f946dc-4c21-4ccd-b78b-f0a5fce94f4d"

Warning

Session ID in the response body is surrounded by quotation marks ("). Some requests may require you to remove them.

Set-Cookie header:

sid=6de74cf1-b0cd-4a06-9dc2-5b215c7543ef; Path=/

Example

Request

Here is how you can create a session id:

login=<...>
password=<...>
saymon_hostname=<...>
url=https://$saymon_hostname/node/api/users/session

curl -X POST $url \
    -H "Content-Type: application/json" \
    -d @- <<EOF
{
    "login": "$login",
    "password": "$password"
}
EOF
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));
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();
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)

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

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

curl -X GET $url -H "Cookie: sid=$session_id"
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));
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();
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)

Response

"a5f946dc-4c21-4ccd-b78b-f0a5fce94f4d"

See Also