Create Session ID
Creates a new Session, which is later used to authenticate other API requests.
If a Session is successfully created, a Set-Cookie header is returned, which sets proper cookie with session ID. The method returns a newly-created session ID.
Request
HTTP Request
Path parameters
No parameters required.
Body parameters
Parameter | Type | Description |
---|---|---|
login | Stringrequired |
User's login. |
password | Stringrequired |
User's password. |
auth-token | String | Authentication token. |
Request body
You can create new session using either a login and password or an authentication token.
Login and password
Authentication token
Response
Response body contains a string with the session ID:
Warning
Session ID 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 session id:
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();
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:
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();