The user session token (legacy) or a refresh token (JMap Cloud)
Optional
organizationId: stringThe JMap Cloud organization id
// Set the user session token for JMap server
JMap.User.setToken("23558109")
.then(userData => {
console.log(`Session token = "${userData.accessToken}""`)
console.log(`The session belongs to ${userData.user.fullName}`)
})
.catch(error => {
if (error === "user.token.invalid") {
console.log(`Invalid token`)
} else {
console.log(`Server error`)
}
})
// Set the user session token for JMap Cloud
JMap.User.setToken("v1.MRq [.....] Rehef72YWws","my-organization-id")
.then(userData => {
console.log(`Session token = "${userData.accessToken}""`)
console.log(`The session belongs to ${userData.user.fullName}`)
})
.catch(error => {
if (error === "user.token.invalid") {
console.log(`Invalid token`)
} else {
console.log(`Server error`)
}
})
JMap.User.setToken
Sets the user session data. Useful if you want to make a call to our Rest API and set the session token by yourself.
This process is a bit different for JMap Server than for JMap CLoud.
For JMap Server, you need to fetch a session token from the REST API, and call JMap.User.setToken without spedifying the organization Id.
For JMap Cloud, you need to fetch a refresh token from the JMap Cloud Rest API, and pass this refresh token, along with the the optional organisation Id, to the JMap.User.setToken method. Beware that a refresh token can only be used once, it is invalidated afterward
Fetching data from a REST API can be done with the curl command-line tool (https://curl.haxx.se/docs/)
a JMap Server example:
will return something like:
a JMap Cloud example:
will return something like: