Skip to main content

Is there a supported way to update Script Extension code using an API? For example, have scripts stored in a GitHub repository, built using GitHub Actions, and then deployed to Airtable. Currently, my team have just been manually copying and pasting code they build locally onto Airtable, which leaves a pretty large hole for human error (even ignoring the tedium of such a task).

I have a horrible workaround that I may use if necessary:

/**
* Fetches and executes the JavaScript file at the provided `path`.
* This can be thought of like:
*
* ```js
* await import(path);
* ```
*
* Except this bypasses CORS and directly injects the remote code.
* Wildly unsafe.
*
* @param {string} path
*/
async function fetchAndRun(path) {
const response = await fetch(path);
const text = await response.text();
eval(text);
}

const myExternalCode = "https://gist.githubusercontent.com/ZacHarroldPartum/fa0f6b6e707c8de3edf725ea0747bba3/raw/2f2fd47a248e8c3954727755ad35ac00193ef113/hello_world.js";

await fetchAndRun(myExternalCode);

The above is quite inefficient and wildly unsafe, but would allow for automated deployment of updates to our scripts by simply updating the file that URL points to. Could potentially store code with an Airtable base instead of a remote URL, but the process is largely the same. 

Hi ​@Zac Harrold,

 

No as far as I’m aware there’s no way to do this via the API. I sympathise though as I too have tried different ways to both centralise and execute scripts that are used often from project to project. We’re often spinning up bases with similar functionality and whilst cloning is fine it doesn’t deal with updating scripts as in your case! Lots of repeated code but not sure there’s a great solution. Security issues aside your solution is hacky but if it works? 🙂 Sorry I can’t be any help but more a ‘I feel your pain’ post 😬


Hi ​@Zac Harrold ,

 

Great question! Right now, Airtable doesn’t have a direct way to update scripts via an API. But here are two options that might help.

 

Option 1: Use Your Own API

One easy way is to put your script logic on your own API or web service. You’d update that API whenever you have new code. Then, in Airtable, you just have a small script that calls your API. That way, you only have to update your API, and Airtable just pulls the latest results. I’m not sure what your scripts currently perform but I suspect this could be a good option.

 

 

Option 2: Add a Manifest for a Bit More Safety

Now, if you really need the script to run inside Airtable because it needs to interact with the user (like asking them to select something), then you can do something similar to what you proposed. Instead of just having Airtable read the code directly from a URL every time, you add a little manifest file. The manifest is just a small piece of information that says which version of the code to use. This gives you a little extra layer of safety and control so you know exactly what version of the code Airtable is running.

 

So basically, if an API isn’t the best fit because you need that user interaction, the manifest approach just adds a nice safety check to what you’re already thinking of doing. Hope that helps!


Hey ​@Zac Harrold,

I would highly suggest Option 1 suggested by Enrique above. Furthermore, you might want to look into n8n (more on n8n here) that should allow you to update Code nodes (scripts) on their own platform via API.

Mike, Consultant @ Automatic Nation 
YouTube Channel