Airtable update records
@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
}
11
this.records = [
  { 
    fields: {
      fieldName: "fieldValue",
      fieldName2: 2,
    },
    id: "airtable_record_id",
  }
]
steps.
update_n_records
This request can accept array more than 10 record objects, it will iterate over the array, and hit the Airtable update_records endpoint with sets of top 10 records. 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.
auth
(auths.airtable)
params
Records

Records to update. This action can accept an array with more than 10 record objects, it will iterate over the array, and hit the Airtable update_records endpoint with sets of top 10 records. 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.

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

The ID of the base API url.

 
string ·params.base_id
Table name

The name of Airtable's table to update.

 
string ·params.table_name
code
async (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
const chunk = require('lodash.chunk');
const BATCH_SIZE = 10; // Airtable API allows to update upto 10 rows per request.

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

async function updateRecords(data){
  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
  };
  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: records_set }));
}

return response_records;