Table of Contents
Setting up
To create records you need three things: the baseId
, tableId
, and an authenticated instance of Flairtable (see sign in tutorial). The tableId
is very easy to find: it's just the
name of the tab in your Airtable base.
The baseId
is a bit trickier. You need to go to the Airtable API docs and click on
the base you wish to use. The baseId is something that's immediately shown.
Lastly you will need to create a column called User
in the table you want to add records to. This is to make sure
that a user can only create/edit/delete rows that he/she made.
The User
column should link to the Users
table you created following the setting up authentication guide.
It should look something like this:
Airtable love
The Create records
call is 1:1 translated to Flairtable. If you prefer their docs (they're really good):
you can just follow along there.
Remember to use the Flairtable SDK, base URL and API key though!
Usage
To create records, use the create
method.
The first argument should be an array of up to 10 record objects.
Each of these objects should have one key, fields
, which contains all of your record's cell values by field name.
You can include all, some, or none of the field values.
Returns an array of record objects created if the call succeeded, including record IDs which will uniquely identify the records within.
Code samples
const authenticatedFlairtable = await Flairtable({apiKey: 'YOUR_API_KEY',}).signIn('YOUR_BASE_ID', 'EMAIL', 'PASSWORD', 'session');const base = authenticatedFlairtable.base('YOUR_BASE_ID');base('YOUR_TABLE_ID').create([{"fields": {}}], function(err, records) {if (err) {console.error(err);return;}records.forEach(function (record) {console.log(record.get('id'));});});
You can also omit the callback
parameter. This will result in a 'thenable' promise.
const base = authenticatedFlairtable.base('YOUR_BASE_ID');base('YOUR_TABLE_ID').create([{"fields": {}}]).then(function(err, records) {if (err) {console.error(err);return;}records.forEach(function (record) {console.log(record.get('id'));});});