Using a Script to Create a record in another base

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

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.

1 Like

This is was I’m trying to achieve also, do you have any form of example?



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)
1 Like

@Alexey_Gusev this is great!
Does this method work with a batch create? or will i have iterate API calls?

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

2 Likes

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?