Print

Include Headers

See below for details on including headers for API Requests using the API Connector add-on for Google Sheets.

Contents

What are API Headers?

Headers are key-value pairs that send extra information about your request to the API server. The server responds with headers as well; it's a two-way exchange. Headers typically aren't directly related to the content of the request, but instead provide metadata to describe the request and handle authorization.

There are many custom headers, but here are a few of the most common:

  • Accept. Tells the API server which format you expect to receive back, e.g. text/html, application/xml, application/json.
  • Authorization. Include authorization credentials like an API key or token.
  • Content-type. Describes the format of the current request or response.

Add a Header

Required headers and header values are generally available in the developer section of your platform. The exact values and syntax for the header depend on each API, so check your API's documentation to see the requirements.

To enter a header, enter the key-value pair into the Headers section of the API Connector form.
headers-addheader

Add Multiple Headers

You may need to include multiple headers in your API request.

Simply add them, one under the other, in the Headers section of API Connector's Create Request screen:
headers-multipleheaders

Delete Headers

If you need to delete a header, you may do so by clicking the red "x" icon that appears on hover.
headers-deleteheaders

Reference a Cell

As an alternative to typing in your headers directly, you can input them into a sheet cell instead, and then reference the cell, e.g. +++Inputs!A1+++ (info).

13 thoughts on “Include Headers”

  1. The API i'm calling requires that an "Authorization" header is added with "Bearer " + access_token, however I don't know how to reference the token provided by the Custom OAuth2 functionality. Is there a way to access the token dynamically?

    Reply
    • Hey Jay! Sure, you can reference the cell containing the token using +++ syntax (info). You can also schedule your requests to run in sequence to make sure that the access token is returned before your second request needs it. However this sounds like you're setting up OAuth2, in which case the custom OAuth2 feature probably makes more sense since it will refresh the access token for you.

      Reply
    • When I use the +++ syntax, it only makes the request for the first header (ie the first bearer token/user account)

      I am trying to aggregate a few user accounts. Each user account has a unique Bearer Token. What should my header section look like to make the same endpoint request but swapping out the Bearer Token each time so that I am getting the results for each user? It

      Reply
      • Sorry, you can only cycle through multiple URLs or multiple request bodies, not multiple headers. You would need to create separate requests for these.

    • You can have the raw API data dump to a source sheet, then pull the data you want into cell D29 in a second summary sheet. Sheets provides a lot of functions for this (VLOOKUP is probably the most popular).

      Another option would be our IMPORTAPI custom function, which lets you run API queries from any cell.

      Reply
  2. Hello.
    I'm trying to get api data from my account in the game. Gives an error after launch:
    "1) hz: Completed with errors
    - We received an error from ******.io (403) show response
    {"message":"no token provided"}"

    I have a key and an id token. where to insert them?

    Reply
    • Hey Paha, every API has their own authentication requirements so you'd need to check their documentation to know where to put the key and token. Most APIs request that keys are inserted into a request header, but it could be in the request URL or request body. There are other variations, too, e.g. the header key could be Authorization or API-Key or something totally different. This article contains more information on authentication for APIs.

      Reply

Leave a Comment

Jump To