Airtable webhook notifications for all updates
@tod
code:
data:privatelast updated:3 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 250,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.
nodejs
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 invocations with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
}
12
// Exit early if this message doesn't have any attachments
if (!("event" in $event.body) || !('attachments' in $event.body.event)) {
  $end("No attachments in this Slack message — not an Airtable update.")
}
// ... or if the attachments don't actually contain Airtable data.
// This filters out any other messages from getting processed through
// the rest of the pipeline.
if (!($event.body.event.attachments[0].title_link.match(/https:\/\/airtable\.com.*/))) {
  $end("No Airtable title_link in this Slack message — not an Airtable update.")
}
steps.
nodejs_1
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 invocations with$checkpoint.
async (event, steps) => {
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
35
36
37
38
}
39
// You'll need to add your Airtable API key and baseId to the 
if (process.env.AIRTABLE_API_KEY === undefined) {
  $end("Please create an environment variable named AIRTABLE_API_KEY under your Pipedream settings")
}

if (process.env.AIRTABLE_BASE_ID === undefined) {
  $end("Please create an environment variable named AIRTABLE_BASE_ID under your Pipedream settings")
}

const Airtable = require('airtable')
const base = new Airtable({apiKey: process.env.AIRTABLE_API_KEY}).base(process.env.AIRTABLE_BASE_ID)

// Used for extracting the baseId and recordId from the Airtable URL
// included in each record update sent to Slack
const titleRegex = /https:\/\/airtable\.com\/(?<tableId>.*)\/(?<recordId>.*)/

// Airtable sends a batch of updates in a single message, but includes
// updates to individual records in Slack message attachments. 
// For each of those attachments (record updates), we construct a JavaScript 
// object that looks closer to what you'd expect to receive from a webhook directly.
$event.updates = []
for (let attachment of $event.body.event.attachments) {
  let { tableId, recordId } = attachment.title_link.match(titleRegex).groups
  console.log(`tableId: ${tableId}, recordId: ${recordId}`)
  let record = await base(tableId).find(recordId)
  let createdTime = record._rawJson.createdTime
  let baseId = process.env.AIRTABLE_BASE_ID
  let updates = attachment.fields.map(slackMessageField => {
    return { 
      field: slackMessageField.title, 
      newValue: slackMessageField.value,
    }
  })
  $event.updates.push({
    baseId, tableId, recordId, createdTime, updates
  })
}