This is part three of our tutorial series on working with the Airtable API in dashdash. To follow along, make sure you’ve completed the previous tutorials.
Creating a new entry in Airtable is a little bit more complicated than just getting it. But don’t worry - in this article we’ll cover
- Creating a JSON object
- Modifying the object to match Airtable’s requirements
- Creating the entry in Airtable using
But first, let’s set up our PostToAirtable view by creating the following header rows:
|B1||Remove square brackets|
|A5||Copy in the entire header row from GetAirtableData, but remove the createdTime header.|
It should look a little like this:
Note: Airtable is a bit funny in a way. When we send data, our table headers must be exactly the same as what is in the Airtable view. For example, if in Airtable the header is
"id", but we send through
"ID", then we will get an error. That’s why it’s always best to just get the headers using the GET request and then just copy them over.
Now, let’s just fill in some dummy data below the headers.
|A6||My first post from dashdash!|
|C6||It’s just easier with dashdash.|
Now we can create our JSON object:
Creating a JSON object
Creating a JSON object in dashdash is very easy. All we need to do is select the header row (so the property for JSON) and the row with our dummy data (values).
Update your PostToAirtable with the following:
Note: For creating entries in Airtable, we don’t need the
id (because there won’t be any as the entry hasn’t been created yet). However, to simplify some steps in a later article, we’ve kept it here.
If you click on the Data Explorer icon in A2, you should see the following:
As we can see, we now have successfully created a JSON object! Before we can send it, we need to modify it slightly to match JSON structure Airtable expects.
Modifying the object to match Airtable’s requirements
If we have a look at how Airtable sends their data, and compare it to how our
RANGE2JSON() function creates the JSON array, we’ll spot two key differences:
Airtable expects what we send is an JSON object (whereas we create a JSON array - as indicated by the square brackets) and that everything is “wrapped” in a
fields object. So we need to:
- remove the square brackets
- add a
We’ll update our PostToAirtable view with the following:
||Removes the square brackets.|
||Puts everything in a
Why aren’t we using
=SUBSTITUTE(SUBSTITUTE(A2,"[",""),"]","") in B2? Well, we only want to remove the first square bracket and the last, and not any in between.
If your view looks similar to the screenshot below, then you’re ready to create a POST request!
Creating the entry in Airtable using
To create the entry in your Airtable account, we just need to do a simple
POST() function. But because we want to be a bit fancy and only POST the entry when the Create button is pressed, we’ll need to wrap it around an
Just add the following in your PostToAirtable view:
||This will create our entry in Airtable as soon as we press click the Create button.|
In the end, your PostToAirtable view should look something like this:
Now all that’s left is to press the Create button, and our new entry will be created! If you click on the Data Explorer icon in D2, you should see the following:
And that’s it! If you update your table in GetAirtableData (or just go to your Airtable account), you’ll see your new entry. Great!
And now that we have an entry there, let’s learn how to update it!
Up Next: Part 4 - Update an entry in Airtable