Dec 16, 2021 11:05 AM
Question for the community: is it possible to write a script that creates a new record in a table from a different base?
Basically I would like to create a button in a few different tables from various bases that, when triggered, runs a script that creates a new record in a table (with some specific fields copied over) in a separate base.
Is something like this possible in Airtable?
Thanks!
-Josh
Dec 16, 2021 01:30 PM
Hi @Josh_Kurz - you can’t do this directly/wholly in the scripting app as the scope of this app is the base that the script runs in. However, you could have a script in Base A use the REST API to create a record in Base B.
Mar 04, 2022 03:38 AM
This is was I’m trying to achieve also, do you have any form of example?
Mar 14, 2022 08:40 AM
const RO_KEY='keyABCDEF111_YOUR_API KEY';
const newRecords={records:[
{fields:{"Name": "record5", "Notes": "Test NEW created"} },
{fields:{"Status": "Todo","Email": "apirest@gmail.com"} }
]}
const options={
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer '+ RO_KEY},
body: JSON.stringify(newRecords)
}
//Test Api
const TAB_PATH='https://api.airtable.com/v0/appYOURBASEID/tabName';
let word=TAB_PATH//+`view=Grid%20view`;
//let word=TAB_PATH+`filterByFormula=Email%3D%22someaddr%40gmail.com%22`
let response = await remoteFetchAsync(word, options)
const pageSummary = await response.json();
output.inspect(response);
output.inspect(pageSummary); //for debug
//let values=pageSummary.records.map(rec=>rec.fields)
//output.inspect(values)
Aug 05, 2022 05:23 PM
@Alexey_Gusev this is great!
Does this method work with a batch create? or will i have iterate API calls?
Aug 06, 2022 12:51 AM
The first argument should be an array of up to 10 record objects. Each of these objects should have one key whose value is an inner object containing your record’s cell values, keyed by either field name or field id.
Returns an array of record objects created if the call succeeded, including record IDs which will uniquely identify the records
Aug 08, 2022 10:26 AM
Thanks @Alexey_Gusev!
If I copy your syntax it works but whenever I attempt to pass this:
{"0":{"fields":{"Creative_Name":"Audio Produced : PRE+POST – ",
"Class":{"name":"Audio"},"Type":{"name":"Produced"},
"Messaging":{"name":"PRE+POST"}}},
"1":{"fields":{"Creative_Name":"Audio Scripted : PRE+POST – ",
"Class":{"name":"Audio"},
"Type":{"name":"Scripted"},"
Messaging":{"name":"PRE+POST"}}},
"2":{"fields":{"Creative_Name":"Promo 1 : POST – ",
"Class":{"name":"AV"},
"Type":{"name":"Promo"},
"Messaging":{"name":"POST"}}},
"3":{"fields":{"Creative_Name":"Trailer : PRE – ",
"Class":{"name":"AV"},
"Type":{"name":"Trailer"},
"Messaging":{"name":"PRE"}}}}
I get a status: 422 “Unprocessable Entity” … is it the index numbers?
Aug 28, 2022 10:28 AM
Hi,
it expects array [ ]
to process
the thing on your quote is an object with numbered properties, whose values represents required data.
you can’t use Attay.from… or spread operator like […your_object ], because it’s not iterable.
There are special 3 commands for that case: Object.keys() , Object values() and Object.entries()
You need values() to get an array of required type
let passeditem={"0":{"fields":{"......
//i put whole object inside variable`
..}
Aug 28, 2022 02:37 PM
WebHooks in automation would be worth a look, as you won’t need your API key, the webhook provides a unique URL to use. I’ve been testing them out and they seem straight forward enough.
Aug 29, 2022 02:58 AM
Can’t agree more. I’m using webhooks for inter-base communication, where syncing tables is too redundant for the task. I’ve set up dedicated base as ‘central connection point’ with a list of org structure units and their webhook links and other stuff, a kind of ‘DNS server’ for central management.
Also, it provides convenient UI to start “parse” request body, without all those “array or object” confusions. 100k is a hundreds of records, maybe even 1000+ for narrow tables - no need to iterate for each 10. I just forget this way because never used it for bulk creation, using ‘sync copy’ instead.