• 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:

    # getting a session token from JMap Server
    curl -X POST "https://my-jmap-server/services/rest/v2.0/session" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"username\": \"jdo@company.com\", \"password\": \"xxx\", \"type\": \"NG\"}"

    will return something like:

    {
    "message": "The result is a NG session info",
    "status": "OK",
    "result": {
    ...
    "sessionId": 23558109, // session id in the Rest API response is the session token.
    ...
    }
    }

    a JMap Cloud example:

    # getting a session token from JMap Cloud
    curl --request POST \
    --url https://api.jmapcloud.io/api/ss/rest/v1/authenticate \
    --header 'accept: application/json' \
    --header 'content-type: application/json' \
    --data '
    {
    "username": "jdo@company.com",
    "password": "xxx"
    }
    '

    will return something like:

    {
    "message": "The result is the access and refresh tokens",
    "result": {
    "accessToken": "eyJhbGciOiJ [.....] 6qwoKzNXMML4oGyNP6Vw_fCC58LCb7YQnY431BaTmxMNswr0HKMN0PQ",
    "refreshToken": "v1.MRq [.....] Rehef72YWws",
    "accessTokenExpireAt": "2022-12-24T17:31:33.429+00:00",
    "accessTokenExpiration": 86400
    }
    }

    Parameters

    • token: string

      The user session token (legacy) or a refresh token (JMap Cloud)

    • Optional organizationId: string

    Returns Promise<JSessionData>

    Example

    // 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`)
    }
    })