Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Jan 28, 2022 09:54 AM
I’m using a custom script to get records form the base I am in. To do this, I am using using:
base.getTable('Incoming');
Now, I’d like to create new records using data from the records in base.getTable('Incoming')
in a table that lives in a different base. How can I reference a different base from this script?
Jan 28, 2022 10:12 AM
Scripting is only aware of its own base. If you want to use scripting to access a different base, you can use the REST API. However, you would not be able to take advantage of any libraries, and you are exposing your API key to all users in the base.
Another option would be to use a script to call a webhook automation in the remote base. Then have script in the remote base create the record.
Jan 28, 2022 10:42 AM
Is there a way to use the API inside of a script? Also, when you mention webhooks, does that mean integrating with another software?
Jan 28, 2022 10:53 AM
Using the REST API from a script is just like using the REST API from anywhere else, except that you cannot use libraries. See the documentation for more info.
The webhook automation is documented here
Jan 28, 2022 10:59 AM
I guess I’m wondering how to access the below (from API docs) in the scripting:
var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('appLeAWrWWE5ctwux');
How can I use the API in a script if I don’t have access to the base I want to send to/from?
Does the script “know” about require('airtable');
?
Jan 28, 2022 11:09 AM
When you use require('airtable')
you are trying to include a library. This will not work. Scripting cannot use libraries. You will need craft the API calls on your own. Depending on your level of coding experience, this might be a large learning curve, or (if you have budget) you may want to hire someone to write this for you.
Why do you want to create new records in a different base? Could you use a synced table instead?
Jan 28, 2022 11:34 AM
I think I can craft them on my own, but I’m still unsure of how to reference the base in the scripting app? Would I have to create a custom React app to do this?
Also, I just saw the “sync table” feature:
Is there a way to do this programmatically?
The issue is that we want to make space in one base by moving or deleting records we don’t need everyday but want to hold on to.
Jan 28, 2022 11:37 AM
You would not create a react app. That is for creating a custom app, not using the REST API. The documentation for the REST API is quite good and has all the information that an experienced developer needs.
Yes, that is the synced table feature that I referred to in my earlier post.
Jan 28, 2022 11:39 AM
But how can I use the API in the script if I can’t use libraries? Where should I use the API?
Jan 29, 2022 09:27 AM
You must build every aspect of the API call without the benefit of helper libraries (i.e., SDKs). It’s very tedious and it places all the integration burden on you and requires a deep understanding of native javascript directives. Don’t do this if there’s a better way, and @kuovonne has already pointed you in that direction - calling an Airtable webhook seems far less complex and requires no API key exposure or API skills.