Connect to an API with Bearer Token Authentication in Airtable

Aug 8, 2024Zayyad Muhammad Sani

In this tutorial, you'll learn how to connect to APIs using bearer token authentication in Airtable. Though we'll use GitHub's API in this tutorial, you can apply the steps you'll learn to other APIs that use bearer tokens for authorization.

What is a Bearer Token?

A bearer token is a secret text value that API services use to authorize users. You can think of it like a password for the API. Many API services allow users to generate bearer tokens after they've signed up. The users can then access the APIs as long as they include the bearer token every time they make an API request.

In the upcoming section, we'll use GitHub's fine-grained personal access tokens to fetch the authenticated user's profile information.

Generate a Fine-Grained Personal Access Token in GitHub

If you already have a bearer token, you can skip this section!

GitHub's fine-grained personal access tokens are bearer tokens that users can configure to access specific API endpoints and resources. We'll create a fine-grained token with the default configuration:

1. Login to GitHub, click your profile image in the top-right corner of the screen, then click Settings.

click-settings-github.png

2. Scroll down the left sidebar, then click <> Developer settings.

developer-settings-github.png

3. Open the Personal access tokens dropdown, then click Fine-grained tokens.

fine-grained-token-github.png

4. Click Generate new token.

generate-new-token-github.png

5. Name the token "Profile info", then give it the following description: "Returns the profile information for the authenticated user."

name-fine-grained-token.png

6. Scroll down the page, then click Generate token.

complete-generate-token-github.png

7. Copy and paste the token somewhere safe, or leave the browser tab open so you can copy it when we use it in Data Fetcher. You can regenerate a token if you forget to copy it.

fine-grained-token-generated.png

Now that we've generated the token, let's install Data Fetcher.

Add Data Fetcher to Airtable

1. Add the Data Fetcher extension to your Airtable base.

2. Once you’ve added the extension, sign in to Data Fetcher or sign up if you don’t have an account.

sign up for data fetcher.png

3. Once you've logged in to Data Fetcher, click Create your first request.

create your first request logo 2 smaller.png

Connect to an API with Bearer Token in Airtable

Follow these steps to set up the request:

1. Under Application, select Custom.

select custom request.png

2. Name the request "Fetch GitHub profile data".

name-github-oauth-request.png

3. Enter https://api.github.com/user under URL. Make sure the request's method is GET.

github-user-endpoint-get.png

4. Click Authorization, then select Bearer Token.

bearer-token-github-user-endpoint.png

5. Copy and paste your fine-grained personal access token into the Token field. If you're not using GitHub, check your chosen API's documentation to find your bearer token.

bearer-token-pasted-github.png

6. Click the Headers tab, then click + Add.

add-header-github-oauth.png

7. Add a User-Agent header with "Data Fetcher" as the value. GitHub requires this header to identify who is making the request. If you're not using the GitHub API, check your API's documentation to see what headers (if any) you need to add.

add-user-agent-header-github-oauth.png

8. Click Save and Run in the bottom right corner.

Mapping Response Fields

Once you've completed the previous steps, Data Fetcher will take you to Response field mapping. On this page, you'll select the fields you want to import from the response data.

response-field-mapping-github-oauth.png

We're going to import the "Login" field.

  • Click Deselect All, then click "Login".
select-login-field.png
  • Click Existing field under "Login", then select "Name" from the dropdown.

import-login-field.png
  • Click Save and Run in the bottom right corner.

Check your table to see the results.

github-username-imported.png

That's all for this tutorial. Here's a summary of how to connect to an API with a bearer token in Airtable:

  • Generate a bearer token from the API service you want to access.
  • Set up the table you'll use for the request in your Airtable base
  • Install Data Fetcher in Airtable.
  • Create a Data Fetcher request and use the bearer token for authorization.
  • Run the request and import data into your table.

Check out our blog to see how you can use Data Fetcher and Airtable to import data from different APIs.

Related Posts

How to Make an HTTP POST Request in Airtable

How to Make an HTTP POST Request in Airtable

Aug 20, 2024

Zayyad Muhammad Sani

Custom Requests
How to Fetch Data from an External API in Airtable

How to Fetch Data from an External API in Airtable

Aug 19, 2024

Zayyad Muhammad Sani

Custom Requests
How to Connect to any OAuth2 API in Airtable

How to Connect to any OAuth2 API in Airtable

Jul 22, 2024

Zayyad Muhammad Sani

Custom Requests