GraphQL Explorer
fulfillmenttools GraphiQL

Altair

Pre-request script for Altair

Creating a new environment in Altair 


Last updated
{
"user": "YOUR-USER-EMAIL",
"password": "YOUR-PASSWORD",
"host": "https://YOUR-TENANT-NAME.graphql.fulfillmenttools.com/graphql",
"apiKey": "YOUR-API-KEY"
}const lastTokenCall = await altair.storage.get("lastTokenCall");
const now = new Date();
if (!lastTokenCall || now - (new Date(lastTokenCall)) > 1800000) {
altair.log("Refreshing token...");
var user = altair.helpers.getEnvironment('user');
var apiKey = altair.helpers.getEnvironment("apiKey");
var escapedPwd = altair.helpers.getEnvironment('password');
escapedPwd = escapedPwd.replace(/\\/g, '\\\\');
escapedPwd = escapedPwd.replace(/\'/g, '\\\'');
escapedPwd = escapedPwd.replace(/\"/g, '\\\"');
escapedPwd = escapedPwd.replace(/\`/g, '\\\`');
await altair.storage.set("lastTokenCall", new Date());
const authUrl = 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=' + apiKey
const authResult = await fetch(authUrl, {
"method": "POST",
"body": JSON.stringify({
"email": user,
"password": escapedPwd,
"returnSecureToken": true
})
}).catch((e) => altair.log(e))
const data = await authResult.json()
altair.helpers.setEnvironment("authToken", data.idToken, true);
altair.helpers.setEnvironment("refreshToken", data.refreshToken, true);
}