Skip to main content
Question

Node.JS in Airtable Scripts


Forum|alt.badge.img+2
  • New Participant
  • 2 replies

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);
});

5 replies

Forum|alt.badge.img+2
  • Author
  • New Participant
  • 2 replies
  • March 13, 2025

 

 

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);});

kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • March 13, 2025

Airtable scripts cannot use external libraries. All code in Airtable scripts must fit in a single file in the code editor. Thus things like require() will not work.


Milan_Automable
Forum|alt.badge.img+3

No, you cannot use external libraries.

There are 3 options to run code with custom libraries, and use it to update Airtable records:

  1. You can use one of Make.com’s JS integrations
  2. You can use a self-hosted n8n with Code node
  3. You can use the Airtable API, run your code and update records in your tables. Then you can host your code anywhere.

Alternatively, for most workloads, you can implement as an Airtable script using the built-in fetch function that you can use to perform HTTP requests. Syntax is slightly different than rp, but you can do more or less the same with it.

I'd love to explore more use-cases of Airtable and automation specific to your business, if you're interested feel free to book a free call at any time that works for you 🙂

-- Best, Milan - Automable.AI


Forum|alt.badge.img+2
  • Author
  • New Participant
  • 2 replies
  • March 14, 2025

Thanks all,

I was able to reconfigure this to use fetch instead and embed the private key directly. My only hangup now is configuring the JWT assertion to send the payload through in the right format. Any ideas on a way to do this within the script vs. setting up an external node?

 

Fortunately, I have already got the subsequent code to pull a list of enrollments verified.


kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • March 15, 2025
tyler wrote:

Thanks all,

I was able to reconfigure this to use fetch instead and embed the private key directly. My only hangup now is configuring the JWT assertion to send the payload through in the right format. Any ideas on a way to do this within the script vs. setting up an external node?

 

Fortunately, I have already got the subsequent code to pull a list of enrollments verified.

Fetch is part of plain JavaScript. That is why you are able to use it in scripting.

If you want to use JWT in Airtable scripting, you will have to find a way to embed the code in you script. Some libraries are small enough that you can dump the minified versions in the scripting editor along with your code. 

If you are using scripting extension versus an automation script, you can get creative using eval().

However your script also appears to access other things that are not available. For example, Airtable scripts cannot access the local file system. (There is limited ability for someone using scripting extension to use input.file Async(), but I don’t think that’s what you want. 


Reply