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 Update 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 update records, use the update
or replace
method. An update
will only update the fields you specify,
leaving the rest as they were. A replace
will perform a destructive update and clear all unspecified cell values.
The first argument should be an array of up to 10 record objects. Each of these objects should have an id property representing the record ID and a fields property which contains all of your record's cell values by field name. You can include all, some, or none of the field values.
Code samples
Update
// A non destructive update callconst authenticatedFlairtable = await Flairtable({apiKey: 'YOUR_API_KEY',}).signIn('YOUR_BASE_ID', 'EMAIL', 'PASSWORD', 'session');const base = authenticatedFlairtable.base('YOUR_BASE_ID');base('Table 1').update([{"id": "ITEM_ID","fields": {"Name": "Hello"}}], function(err, records) {if (err) {console.error(err);return;}records.forEach(function(record) {console.log(record.get('Name'));});});
Raplace
// A destructive replace callconst authenticatedFlairtable = await Flairtable({apiKey: 'YOUR_API_KEY',}).signIn('YOUR_BASE_ID', 'EMAIL', 'PASSWORD', 'session');const base = authenticatedFlairtable.base('YOUR_BASE_ID');base('Table 1').replace([{"id": "ITEM_ID","fields": {"Name": "Hello"}}], function(err, records) {if (err) {console.error(err);return;}records.forEach(function(record) {console.log(record.get('Name'));});});
You can also omit the callback
parameter. This will result in a 'thenable' promise.
const base = authenticatedFlairtable.base('YOUR_BASE_ID');base('Table 1').replace([{"id": "ITEM_ID","fields": {"Name": "Hello"}}]).then(function(err, records) {if (err) {console.error(err);return;}records.forEach(function (record) {console.log(record.get('id'));});});