✨ Instagram integration is live! Tutorial

How to Connect to a GraphQL API in Airtable

Jul 27, 2021Andy Cloke

In this guide, we will learn how to connect to a GraphQL API in Airtable using the Data Fetcher extension. GraphQL is a query language for APIs made by Facebook that is growing in popularity. We will connect to an open-source GraphQL countries API to import country data in Airtable. You can use the same approach to connect to other GraphQL APIs in Airtable, such as the Shopify Admin API or the Github API.

Install Data Fetcher

Install Data Fetcher from the Airtable marketplace. Data Fetcher is a free Airtable extension that lets you connect to any JSON or GraphQL API. 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

Connect to GraphQL API in Airtable

On the home screen of the Data Fetcher extension, click 'Create your first request'. Requests in Data Fetcher are how you import data to or send data from your Airtable base.

click-create-your-first-request.png

On the create request screen in Data Fetcher, for Application, select 'Custom'.

custom-application-selected.png

Enter a Name for your request, e.g. 'Import Countries'.

Set the request method to POST. GraphQL APIs always require the request method to be POST.

Enter the following URL. This is the base URL for the countries GraphQL API we are using.

https://countries.trevorblades.com/

graphql-url-name-method.png

Add a GraphQL request body by entering the GraphQL query you want to use, as well as any variables.

{
  countries {
    code
    name
    emoji
    capital
    continent {
      name
    }
    currency
  }
}

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

output-table-1.png

Click 'Save & Run'.

graphql-save-run.png

The request will run and the Response field mapping modal will open. This is where you set how the available fields in the GraphQL API response should map to fields in the output table. For each field name in the response, you can either import or filter it. For an imported field, you can set whether to map them to an existing field or create a new field. You can also set the field type for each new field.

Once you are happy with the mapping, click 'Save & Run'.

graphql-response-field-mapping.png

Data Fetcher will create any new fields in the output table, then run the request and import the data from the GraphQL API in Airtable.

Screenshot 2021-07-27 at 12.04.02.png

If there is a unique id field in the GraphQL API response, you can import that and set it as the Update based on field in the 'Advanced settings'. This means even if you move records around in Airtable, Data Fetcher will still be able to match up data from the API response with records in the output table.

Import Data from GraphQL API in Airtable on a Schedule

At the moment, we have to click 'Run' in order to import the data from the GraphQL API. We can use Data Fetcher's scheduled requests feature to automatically import the data every 15 minutes/ hour/ day etc.

In Data Fetcher, scroll to Schedule and click 'Upgrade'.

table-1-schedule-upgrade-button.png

A new tab will open where you can select a plan and enter your payment details to upgrade.

Screenshot 2021-12-29 at 10.25.19.png

Return to the Data Fetcher extension and click "I've done this".

table-1-schedule-ive-done-this-button.png

Click 'Add API key' in order to add your Airtable API key. You can find your Airtable API key here.

Group 11(1).png

Enter your Airtable API key and click 'Save'.

save-airtable-api-key.png

Enable Schedule this request.

schedule-data-fetcher-request.png

Select how often you want the request to run, e.g. 'Every 15 mins'. Click 'Save' The request will now run on the schedule and import the GraphQL API data automatically.

Group 11(2).png

Other GraphQL APIs

For this guide, we used this public countries GraphQL API. Here is a list of public GraphQL APIs you might want to try instead, following the same approach as above.

data fetcher graphql query body.png

Other Recent Posts

Get a Favicon from a Website in Airtable

Get a Favicon from a Website in Airtable

Oct 27, 2022

Rosie Threlfall

Icon