With the new APIs & Services feature, you’re able to save the base URL for any REST API which will allow you to easily reuse and modify your request. We’ll go over an example of this with sorting and filtering Airtable query results.
For this example, we’ll be using a simple Base with two Tables that was created to keep track of favorite album releases.
Once your Base is ready, you can go to Airtable’s API Documentation found under the ‘Help’ button in the top right corner of your Base.
Make sure you check the ‘show API key’ checkbox to generate your key — we’ll save this in the Global Variables settings back in Draftbit.
For previous Airtable tutorials, we’ve had you copy and paste the entire URL in the example generated, but for this one, we’re going to leave out the
2019 (the Table Name) at the end.
If you go further down to the
List Records section of the documentation, you’ll see a section discussing the ways you can filter and sort your query. Keep this open, we’ll come back to this later.
To configure this in the APIs and Services, open the Project Settings by clicking the gear in the column on the left of the Builder and go to the Variables tab. Give the new variable a name (Key), paste your API Key in the Value section and click the ‘Add’ button.
Next, click the Data button on the left-hand side of the builder and select
Rest API under the Add a Service header. Here is where you will:
- Give your Service a Name
- Paste the Base URL into the
Base URLinput (make sure there's no
/at the end)
- Add your API key — Create a new Header, make sure its key is 'Authorization' and select your Global Variable from the Value dropdown.
Next, you can create the endpoint for your query. Airtable has made it super easy to generate the proper URL to filter and sort your results with its API Encoding Tool (If you access this tool directly from the Airtable API documentation, it’ll have the Base ID and Table fields pre-populated for you). Once you’ve filled in the fields you need, you can copy the portion of the URL after the Base ID to use in Draftbit.
Here’s an example to generate a URL that will return a list of Albums in the 2020 Table sorted by the release month in ascending order.
Once you’re back in Draftbit, create a new endpoint in your Airtable service and paste the necessary portion of the URL into the
Add Path & Params input. Test the request and you’ll see the results of your sort/filter appear!
Make sure to refer back to Airtable’s API documentation to see the full list of query parameters you can use in your own requests!