Hello is it possible to use NodeJS coding within Airtable Scripts? I have a library of API codes that were configured with NodeJS. However, I seem to have issues with Axios and request-promise…
Code Example:
Code Example:
Code Example:
/////////////////////////////
// Change these parameters //
/////////////////////////////
const API_UID = 'Oauth App UID from account settings';
const PRIVATE_KEY = 'path/to/private/key.txt';
/////////////////////////////
const jwt = require('jsonwebtoken');
const rp = require('request-promise');
if (!global['URL']) {
global.URL = require('url').URL;
}
const fs = require('fs');
let privateKey = fs.readFileSync(PRIVATE_KEY);
let uri = new URL(`[REDACTED]`);
let aud = `${uri.protocol}//${uri.hostname}`,
time = Math.trunc((new Date().getTime()) / 1000);
let claim_set = {
iss: API_UID,
aud: aud,
scope: 'admin_read admin_write',
exp: time + 60,
iat: time
};
let assertion = jwt.sign(claim_set, privateKey, {algorithm: 'RS256'});
let payload = {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: assertion
};
rp({
method: 'POST',
uri: uri.href,
body: payload,
json: true })
.then(function (parsedBody) {
console.log(parsedBody);
return parsedBody; })
.catch(function (err) {
console.log(err);
});