Airtable update records example
@dylburger
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
format_airtable_records
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
}
10
this.records = [
  { 
    fields: {
      "TEST": "TEST NAME",
    },
    id: "recOkepaWtxPRK5j5",
  }
]
steps.
update_records
auth
to use OAuth tokens and API keys in code via theauths object
(auths.airtable)
params
Records

An array of update objects. Each of these objects should have two properties: 1) fields, which contains all of your record's cell values by field name, and 2) id, the ID of the record in Airtable you'd like to update. You can include all, some, or none of the field values.

{{steps.format_airtable_records.records}}
array ·params.records
Base ID

Your Airtable Base ID

 
string ·params.base_id
Table Name

The name of your table in Airtable

 
string ·params.table_name
Optional
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
}
34
const chunk = require('lodash.chunk');
const BATCH_SIZE = 10; // Airtable API allows to update up to 10 rows per request.

const { records } = params
if (!records || !records.length) {
  console.log("No records found")
  return
}
const size = records.length; 
const response_records = []

async function updateRecords(records){
  const config = {
    method: "patch",
    url: `https://api.airtable.com/v0/${params.base_id}/${encodeURIComponent(params.table_name)}`,
    headers: {
      Authorization: `Bearer ${auths.airtable.api_key}`,
    },
    data: {
      records,
      typecast: params.typecast,
    }
  };
  return await require("@pipedreamhq/platform").axios(this, config);
};

const records_sets = chunk(records, BATCH_SIZE);
for (const records_set of records_sets) {        
  response_records.push(await updateRecords(records_set));
}

return response_records;