make an airtable tool

so.

Airtable is cool. We all know this. Even those of us who momentarily resist its charms give in, ultimately.

But it is definitely a little bit difficult to enter data into Airtable whenever and wherever you'd like. Slack offers users a comparatively greedy and accepting interface, sucking in data with delight. Airtable resists.

In part this is due to Airtable's demands for structure. If you've ever tried to use Slack to store and retrieve ideas, you'll realize that there's a downside to its gleeful acceptance of all your random thoughts and links and media: you can never find it again.

So let's try to have our cake and it too.

We're going to code some different ways of getting stuff into Airtable. Including a Slack slash command.

using the shell

Airtable actually makes it ridiculously easy to add things with shell scripts. If you go to the Airtable API site (and have logged in), you'll find loads of starter code.

So log in, create an API key (and note it down somewhere safe like 1Password), and start looking around at the shell commands for finding and creating records. We're going to focus on creating records first, because, as we said earlier, this is the biggest pain point (it's actually not so bad viewing your data in Airtable once it's there).

You'll end up seeing a command that looks something like this:

curl -v -XPOST https://api.airtable.com/v0/appXXXXXXXXXXXX/links \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{
  "fields": {
    "Name": "Top 5 things every Ableton Push 2 beginner should understand - YouTube",
    "URL": "https://www.youtube.com/watch?v=Vv5hA226s3I",
    "Tool": [
      "Ableton Live"
    ],
    "Medium": [
      "Music"
    ]
  }
}'

So let's grab this code and tweak it. Don't copy the above code--copy the code you see in your airtable.com/api interface and paste it into Atom for starters. Once it's there you can tweak the properties. You don't want to tweak the property names (the words "Name" and "URL" and "Tool" in the example above), because these need to match the columns you have in Airtable exactly, but you definitely want to change the values because that's how we're going to add new records with characteristics the we define (either by asking for user input or by scraping other sources of data).

You don't absolutely need to understand every last bit of the command, but let's take a second to unpack what's happening here.

Once you hit enter, this command should send a new record to your Airtable base. And if you only need to change a single word or two to make this useful to you--for instance if you are populating the table with records that have a single URL that may vary (a YouTube link, for instance), but other info that's always the same (i.e. everyone of these links is a task assigned to your name, or a specific LL lab, for instance), then you can get what you need done pretty easily with a shell script.

Try creating a file called url2at.sh (or something better than that), and type in the following code

 #!/bin/bash

curl -v -XPOST https://api.airtable.com/v0/appXXXXXXXXXXXX/links \
  -H "Authorization: Bearer V" \
  -H "Content-Type: application/json" \
  --data '{
  "fields": {
    "Name": "another of my links",
    "URL": "'$1'"
  }
}'


echo "\nsent $1 to airtable"

So what we're doing here is taking the same command we used above and then adding in the first argument we pass in to the script. To run it we need to 1. Make it executable by entering chmod 755 url2at.sh (from within the directory that contains it, otherwise you'd need to enter the full path to url2at.sh). 2. Type in the command: ./url2at.sh www.youtube.com. It should work!