Authentication is the first step of programmatically obtaining an JSON Web Token to use with the API.

  • Endpoint: /cloud-service-auth/auth
  • Method: POST
  • Body:
    {
        name, // your@mail.com
        password,
        lifetime: 1800000, // millis -> 30mins
        code: null,
        termsOfUse: null // TODO
    }

JavaScript (NodeJS) Example:

const getInitialToken = () => {
    const headers = new fetch.Headers({
        "Content-Type": "application/json;charset=UTF-8"
    });

    return fetch(config.baseurl + "/cloud-service-auth/auth", {
        method: "POST",
        headers: headers,
        body: JSON.stringify({
            name,
            password,
            lifetime: 1800000, // millis -> 30mins
            code: null,
            termsOfUse: null
        })
    }).then(resp => resp.json());
};

Authorization

With the resulting token from the Authentication request, we can now upgrade this token to obtain a token with a context, to be used with further API requests.

  • Endpoint: /cloud-service-auth/auth
  • Method: POST
  • Body:
    {
        accountIds: [ /* list of account UUIDs */ ]
    }

JavaScript (NodeJS) Example:

 const upgradeToken = (initialToken, ids) => {
     if (!initialToken.value) {
         throw new Error("Missing JWT");
     }

     const headers = new fetch.Headers({
         "Content-Type": "application/json;charset=UTF-8",
         "Authorization": "Bearer " + initialToken.value
     });

     return fetch(config.baseurl + "/cloud-service-auth/auth", {
         method: "POST",
         headers: headers,
         body: JSON.stringify({
             accountIds: ids
         })
     }).then(resp => {
         if (resp.ok) {
             // do something with the token here
         } else {
             console.log(resp);
             throw new Error("Error upgrading JWT");
         }
     });
 };