Skip to main content

Save this helper as get_auth_token.js. Use Node.js 18+ and enable ES modules (for example, "type": "module" in your project's package.json). Set EMAIL, PASSWORD and, when required, a current TOTP_CODE in the environment. Do not commit credentials or log the returned token. Calling getToken() returns the tokens.accessToken string, not the illustrative success object retained below from the source.

Node.js 18+
export const getToken = () => {
const url = "https://maestro.dadosfera.ai/auth/sign-in";
const data = {
username: process.env.EMAIL,
password: process.env.PASSWORD,
totp: process.env.TOTP_CODE,
};

return fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => {
if (response.ok) return response.json();
else throw response.statusText;
})
.then((data) => data.tokens.accessToken);
};
{"success":true}

Configure request options

In this step, it is necessary to configure some request parameters in the options object. In the data object, it is necessary to pass the credentials to get the token.

Build the request

Using the settings build the request.