Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Mar 04, 2022 03:36 AM
Hi, I’ve trying to create an automation that will create a record in one base from and automation in another base, while I understand scripts as base bound I also understand I can do this wit the API.
So I’ve been looking at the API ref and it give you the basic JAVA to do this but!
The Code:
let inputConfig = input.config();
output.set(’’,${inputConfig.FistName}
);
let fn_var = ${inputConfig.FistName}
;
output.set(’’,${inputConfig.Surname}
);
let sn_var = ${inputConfig.Surname}
;
output.set(’’,${inputConfig.StartDate}
);
let sd_var = ${inputConfig.StartDate}
;
output.set(’’,${inputConfig.StartLocation}
);
let sl_var = ${inputConfig.StartLocation}
;
output.set(’’,${inputConfig.LineManager}
);
let lm_var = ${inputConfig.LineManager}
;
output.set(’’,${inputConfig.JobTitle}
);
let jt_var = ${inputConfig.JobTitle}
;
output.set(’’,${inputConfig.PersonalEmail}
);
let pe_var = ${inputConfig.PersonalEmail}
;
output.set(’’,${inputConfig.EmploymentType}
);
let et_var = ${inputConfig.EmploymentType}
;
var Airtable = require(‘airtable’);
var base = new Airtable({apiKey: ‘’}).base('’);
base(‘IT-SL’).create([
{
“fields”: {
“First Name”: fn_var,
“Start Date”: sd_var,
“Start Location”: sl_var,
“Surname”: sn_var,
“Line Manager”: lm_var,
“Job Title”: jt_var,
“Personal Email”: pe_var,
“Employment Type”: et_var,
“Location”: sl_var
}
},
], function(err, records) {
if (err) {
console.error(err);
return;
}
records.forEach(function (record) {
console.log(record.getId());
});
});
And this is the error:
ReferenceError: require is not defined
at main on line 19
Mar 04, 2022 11:24 AM
Hi @IT_Departmenrt - it looks like you are mixing code for an external REST API call and an “internal” script that you might use in an automation or script block. Have a look here for the internal scripting documentation:
Or take a look at my blog where I have written up some practical scripting examples.
The error message you are getting relates to these lines:
var Airtable = require(‘airtable’);
var base = new Airtable({apiKey: ‘’}).base('’);
You don’t need to bring in the API client on scripts or automations so these lines are not required (but just removing these probably won’t fix your errors - there’s more going on there).
Mar 04, 2022 11:27 AM
Follow up - if you want to create records in another base using the REST API, don’t use the Airtable client (as above), but use vanilla JS code, e.g. fetch
to POST
to your second base.
Aug 08, 2022 11:53 AM
Hey @JonathanBowen do you have an example of that handy? Specifically, i’m looking how to execute a POST request from scripting blocks to create records in another base in batches…meaning: i first create an array of 10 records, then execute 1 post request – as opposed to making 10 different API calls