How to Run a Curl Command in Airtable

Jan 23, 2024Andy Cloke

In this guide, you'll learn to run cURL commands in Airtable using the free Data Fetcher extension. This allows you to connect to any REST API and import external data into Airtable.

What are cURL commands?

cURL (Client URL) commands are a standardised way to interact with servers and transfer data through the command line. It's a powerful tool widely used for testing, debugging, and
interacting with APIs.

All cURL commands will start with "curl ". The most basic example of a cURL command is:

curl http://example.com

This will perform a simple GET request to the http://example.com URL.

One of the most common places you will see cURL commands is API documentation. Many API docs will show you code examples in different languages (e.g. Python) and cURL. For example, the OpenAI list models endpoint shows us the request as a cURL command here:

openai list models curl command example.png

If you want to follow along with this tutorial, you can copy it from below:

curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer $OPENAI_API_KEY"

How to run a cURL command in Airtable

Once you've found the cURL command that you need to run in Airtable, add the Data Fetcher extension to your base from the Airtable marketplace.

After the extension launches, sign up for a free Data Fetcher account by entering a password and clicking Sign up for free.

Group 1Data Fetcher Sign Up .png

Requests in Data Fetcher are how you connect to any API in Airtable. On the home screen of the Data Fetcher extension, click Create your first request.

click-create-your-first-request.png

For the Application, select Custom.

custom-application-selected.png

Now paste the cURL command into the URL input. The cURL command will be automatically imported into the current request, including URL, headers and any option options.

cURL command imported to airtable.png

Most APIs will require some type of authorization, such as an API key. For our OpenAI request, we need to replace the bearer token with our OpenAI API key.

Click on the Authorization tab, then replace the Token with your Open API key. If you do not have one yet, click Create new secret key in the OpenAI dashboard here.

openai curl command authorization token.png

Your cURL command may use a header or parameter for authorization, so check the Parameters and Headers tabs. Some APIs will not have any authorization, so don't worry if you can't find it.

Select the Output Table & View that you want to import the data into.

output table and view - table 1.png

Click Save & Run in the bottom right-hand corner.

save and run curl command.png

The first time you run the cURL command, the Response Field Mapping modal will open. This is where you set up how the fields in the API response are imported into the fields in your Airtable table.

For this example, we will deselect all fields by clicking Deselect all. Then we'll select just the Id field and map this to a new field called "Id".

Once you are happy with the field mapping, click Save & Run. Data Fetcher will create the new "Id" field and execute the cURL command again in Airtable. The data from our third-party API is imported into our output table.

openai models imported into Airtable.png

Use Airtable values in cURL command

We've now imported and run a cURL command in Airtable. We can use values from the Airtable base in the cURL command, e.g. if the cURL command is for looking up stock prices, and we have a table of stock tickers. Read this guide to using table values in Data Fetcher requests.

Schedule a cURL command in Airtable

If you want to schedule your cURL command to run automatically in Airtable, you can do that by scheduling the request. This is a paid feature, so will need to upgrade your workspace first. The cURL command will then run automatically, even when you are not logged into Data Fetcher / Airtable or do not have the base open.

Run a cURL command in Airtable when base changes

Data Fetcher can also execute the cURL command in Airtable whenever the base data changes. To set this up, add a request trigger. For example, you can run the cURL command whenever a new record is created.

Related Posts

How To Import Data into Airtable When a Record is Updated

How To Import Data into Airtable When a Record is Updated

Oct 17, 2023

Rosie Threlfall

Currency ConversionNo-CodeAirtable