Connect to a GraphQL API in Airtable

In this guide, we will learn how to connect to a GraphQL API in Airtable using the Data Fetcher app. 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

Connect to GraphQL API in Airtable

  • On the home screen of the Data Fetcher app, click 'Create request'.
  • On the create request screen, enter the request name 'Fetch 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/

{"query":"query { countries { code name emoji capital continent { name } currency }}"}

  • Set the 'Output Table' to the table you want to import the countries into.
  • Set the 'Output View to the view you want to import the countries into.
Screenshot 2021-07-27 at 11.53.07.png
  • Click 'Run'. You'll see a loading message while the request runs, then the response field mapping modal will open. This is where we select which fields from the API response to keep and how they should map to the fields in the output table. Click 'Show response' on this modal to see the actual response.
  • Click 'Filter all' to deselect all fields, then select the following fields and data types:

Response Field

Data type

Use table field

Or, create field:

data.countries.code

Single line text

Code

data.countries.name

Single line text

Name

data.countries.emoji

Single line text

Emoji

data.countries.capital

Single line text

Capital

data.countries.continent.name

Single select

Continent

data.countries.currency

Single line text

Currency

Screenshot 2021-07-27 at 11.59.11.png
  • Click 'Confirm'. Data Fetcher will create the new fields in the output table, then the request will run again and the data will be imported from the GraphQL API into Airtable!
Screenshot 2021-07-27 at 12.04.02.png
  • Click 'Save'.