Using Airtable with Dexter

Summary

Use an HTTP GET and POST requests to read data and send data from an Airtable base. This snippet is set up to work with Airtable’s User Research template, but can be adapted to your own tables easily.

Snippet

// Variables
! var airtable_api_key = <<YOUR_API_KEY>>
! var airtable_base = <<YOUR_BASE>>
 
// Person Variables
+ set vars
- <set name=Michael>
^ <set number=1111111111>
^ All set! Sending to Airtable... {@ add person}
 
// Add Person
+ add person
$ POST https://api.airtable.com/v0/<bot airtable_base>/People/ {"headers": {"Authorization": "Bearer <bot airtable_api_key>", "Content-Type": "application/json"},"body": {"fields": {"Name": "<get name>","Phone": "<get number>"}}}
* ${{__status}} != 200 => Error: ${{error.message}}
- Sent. We'll be in touch!
 
// Get Person
+ get person #
$ GET https://api.airtable.com/v0/<bot airtable_base>/People/?api_key=<bot airtable_api_key>
* ${{__status}} != 200 => Error: ${{error.message}}
- ^link("${{records.<star>.fields.LinkedIn Profile}}","${{records.<star>.fields.Name}}")
 
// Get People
+ get people
$ GET https://api.airtable.com/v0/<bot airtable_base>/People/?api_key=<bot airtable_api_key>
* ${{__status}} != 200 => Error: ${{error.message}}
- ${{#records}}
^ Name : ${{fields.Name}}\n
^ Phone : ${{fields.Phone}}\n
^ Profile : ${{fields.LinkedIn Profile}}\n <send>
^ ${{/records}}

Explanation

Airtable User Research

Use the examples above as a guide to getting and setting data with Airtable. This snippet is specifically designed to work with Airtable’s User Research template, to collect basic data from users and then return it. This is a basic framework for more complex interactions.

The // Variables section is where you can add your API key and base ID from Airtable. Grab your base ID from their API and your key from your Account Page and replace <<YOUR_API_KEY>> and <<YOUR_BASE>>.

Under // Person Variables you'll find the variables you’ll need to set in the script for this snippet to work. You’ll probably want to take your users through an onboarding flow shown in our Onboarding Bot walkthrough to collect this info. The // Add Person section shows you an HTTP Post Request with a body. You can always add more data, like Company and LinkedIn profile.

The text below // Get Person shows you an HTTP Get Request for grabbing a specific record. You can also use Airtable’s robust API to search, filter, and return data from Airtable. If you say get person 2 the bot will send back the name of the person in row 2 your table with a link to their LinkedIn profile.

The // Get People section shows you an advanced example using Mustache Tags, which sends back all records. Be careful, if you have a lot of records, this will come back as a lot of individual messages.