How to consume any JSON API using Google Sheets, and keep it up-to-date automagically (2024)

How to consume any JSON API using Google Sheets, and keep it up-to-date automagically (1)

Google Sheets are very powerful when you know how to use them. You can do so much with those, and at Unly, we rely on them to automate many things, without relying on developers to build custom tools. #productivity

Most of today’s online services provide ways of extracting data into a spreadsheet, whether it’s CSV, Google Sheets, Excel, etc.

But we often run into limitations when using such services, because they do not always export data the way we’d like them to.

Now, imagine if you could just plug your spreadsheet to any API, extract exactly what you want, the way you want, and use the data however you want with any other service of your liking. Sounds nice right?

We recently encountered such limitations with online services such as PipeDrive and TypeForm

PipeDrive limitations:

We wanted to export our PipeDrive contacts to a spreadsheet.
But the online export feature would not allow us to have two distinct columns for first name and last name, it would just merge both together and that was an issue for our sales team.

Such limitation sounds silly, but it actually impacted the productivity of our sales team. To get around this, we connected Google Sheet to PipeDrive API directly, to get back control on our data.

Now, let’s see how we do that! We’ve put together a very straightforward example. If you want to play around with it we encourage you to make a copy! (File > Make copy)

Spreadsheet example:

https://docs.google.com/spreadsheets/d/1qQg3p_JG7Tirv14z8JXcs4sehsOafBW9FmAkTVVolIc

Spreadsheet explanation:

In this Google Sheet, look at the A1 cell, that’s where the magic is hidden!

=ImportJSON("https://jsonplaceholder.typicode.com/todos", "/", "noInherit,noTruncate,noPrefixHeaders", Settings!$B$1)

This single line basically fetch the jsonplaceholder.typecode.com API.
(which doesn’t do anything meaningful besides displaying “todos”).
Then, it parses the JSON data returned by the API and display them below. Boom!

How to consume any JSON API using Google Sheets, and keep it up-to-date automagically (4)

How does it work?

Make a copy using File > Make copy if you haven’t done that already. Making a copy will also copy the scripts that are behind the function.

In the Script Editor, you will see those 2 scripts (Tools > Script Editor):

  1. ImportJSON.gs is the script that does most of the magic, basically fetch the data, parse them and display them. It’s open source (GNU v3)
  2. triggerAutoRefresh.gs is a custom script we wrote which updates the cell B1 in the “Settings” sheet, it’s a simple trick to force the sheet to refresh when the function is triggered. It is configured to refresh upon page loading for this example, and not on a regular interval (in order not to spam the API), but refreshing on a regular interval is easily doable.

I won’t explain here what the ImportJSON does, if you want to deep-dive then take a peak at https://blog.fastfedora.com/projects/import-json which gives a good overview of the features (even if it’s marked as outdated, it’s the best documentation I’ve found)

Keeping the data up-to-date automatically

If you made a copy you probably noticed it doesn’t refresh on its own. That’s because even though the scripts were copied, the triggers were not.

You have to add them yourselves, it’s pretty simple:

  1. Go to https://script.google.com/home/all
  2. Select your project (should be “TEMPLATE — Google Sheet to JSON API”)
  3. Go to Project details > Triggers (see below)
  4. Add trigger (by default it adds a trigger on the “Spreadsheet open” event)
  5. Select the triggerAutoRefresh function
  6. Select “Event source: Time driven”, select a 5 minutes interval and voilà!
How to consume any JSON API using Google Sheets, and keep it up-to-date automagically (5)

That’s it! Your spreadsheet will now be updated every 5 min due to the trigger, which will write a new random value in the cell Settings$B$1 which in turn will trigger a refresh of the ImportJSON API calls, that will refresh the displayed data!

We wrote another article which showcases Typeform.
In this demo you’ll see how Google Sheets can be used to fetch real-time data from an API, as those data are created by yourself.

How building our own “Typeform to Google Sheets connector” improved our productivityEmpowering collaborators to analyse data from Typeform, without involving developersmedium.com

There are a few limitations with this kind of usage. It’s very simple to consume an API that doesn’t require an authentication, such as the one used in the example. If you need authentication, then things can get harder.

For PipeDrive for instance, since they allow authentication through a api_token to send as GET parameter (query string), it’s pretty simple to configure:

=ImportJSON(“https://api.pipedrive.com/v1/persons?start=0&api_token=your_token&limit=10000&filter_id=1", “/data/first_name”, “noInherit, noTruncate”)

Very simple. Beware of whom you share that sheet with though, they’ll be able to read your API token.

Word of caution, if you have the ability to decide what permissions that token grants, then only allow what you use. For instance, it doesn’t make sense to use a token with write permissions if you only use it to visualize your data.

If you get stuck with authentication, there are other workarounds, such as UrlFetch (OAuth). But it won’t cover all use-cases either.

The ability to consume JSON API through a Spreadsheet is very powerful.
At Unly, it gives our sales and marketing teams the ability to consume online services, without needing our developers’ intervention.

We’ve used this trick for a few months and it hasn’t let us down, we hope it will help you as much as it has helped us!

How to consume any JSON API using Google Sheets, and keep it up-to-date automagically (2024)

FAQs

How to consume any JSON API using Google Sheets, and keep it up-to-date automagically? ›

Using Functions for Automatic Date Entry

The TODAY() function automatically enters the current date into a cell. Every time you open the spreadsheet, the date will update to the current date. To use the TODAY() function, simply select the cell where you want the date to appear and type =TODAY().

How do I get Google Sheets to automatically update dates? ›

Using Functions for Automatic Date Entry

The TODAY() function automatically enters the current date into a cell. Every time you open the spreadsheet, the date will update to the current date. To use the TODAY() function, simply select the cell where you want the date to appear and type =TODAY().

How to pull data from API into Google Sheets? ›

Substitute own file ID and API key into the request URL.
  1. Open up Google Sheets and click Extensions > API Connector > Open > Create request.
  2. Create a new tab and click Set current to use that tab as your data destination.
  3. Name your request and click Run. A moment later you'll see your file in Google Sheets.
Jan 3, 2024

How do you generate a date in Google Sheets? ›

For example, DATE(119,2,1) will create a date of 2/1/2019. For years 1900 to 9999, Google Sheets will use that value as the year. For example, DATE(2019,1,2) will create a date of 1/2/2019. For years less than 0 or greater than 10,000, Google Sheets will return the #NUM!

How do I extract data from JSON in Google Sheets? ›

Import JSON to Google Sheets with Lido (Easiest Method)
  1. Create a FREE Lido Account. ‍ In order to use Lido's IMPORTJSON function, first sign up for an account at https://www.lido.app/go/signup. ‍
  2. Write your IMPORTJSON Formula. Open a new Lido spreadsheet once you have made and account. ‍

How do I import JSON API into Google Sheets? ›

After installing Apipheny, open a Google Sheet. In the menu click Extensions > Apipheny > Import API to open the API Connector. If you haven't already, sign up for a developer account on your API of choice, read the API documentation, and get your API URL, endpoint, parameters, key, and headers.

How to get JSON data from Google Sheets? ›

To access the JSON data of a Google Sheet, you need to first publish it to the web. To do this, go to the "File" menu and select "Publish to the web". In the dialog box that appears, select the sheet you want to publish, and then select the "Comma-separated values (. csv)" format.

Can I call an API from Google Sheets? ›

Using Google Apps Script, we can connect a Google Sheet to a REST API and retrieve data from that API (for example, Numbers API) into our Google Sheet. Establishing Google Sheets REST API Integration can be illustrated with an example of calling a REST API called Numbers API from Google Sheets.

Can we call API from Google Sheets? ›

Sync REST API data sources and automate data refreshes within Google Sheets, streamline workflows, and most importantly - save time. Apipheny is a powerful no-code REST API connector that makes it easy to make API calls from Google Sheets.

What is the best API connector for Google Sheets? ›

Data Connector is the API connector of choice! Data Connector is the ONLY Add-on of it's kind that gives you OAuth2 connections, JMESPath™ and other filters on it's free tier. Other Add-ons make you pay for those features.

How to automatically insert date and timestamp in Google Sheets? ›

Use Ctrl + Alt + ⇧ Shift + ; to enter time and date.

How do I insert an automatic date in Google Docs? ›

To add a date chip, type:
  1. @today.
  2. @tomorrow.
  3. @yesterday.
  4. @date.
  5. A specific date, such as @Jan or @1/1/2021.
  6. A relative date, such as @monday , @next tuesday , or @last wednesday.

How to get day from date in Google Sheets? ›

Extracting day from date
  1. 2. '= TEXT(Date, “DD”) In this case DD will always be a two-number day of the month. ...
  2. 3. '= TEXT(Date, “DDD”) This formula will determine the shortened name of the day of the week, for example: Mon, Tue, Wed etc.
  3. 4. '= TEXT(Date, “DDDD”) It allows us to get a full name of the day of the week.
Oct 3, 2023

Can I use JSON in Google Sheets? ›

However, Google Sheets do not have native support for importing JSON content into a file. The import options available out of the box are: IMPORTXML: Imports data from any of various structured data types including XML, HTML, CSV, TSV, and RSS and ATOM XML feeds.

How do I enable API in Google Sheets? ›

Enable an API
  1. Go to the API Console.
  2. From the projects list, select a project or create a new one.
  3. If the APIs & services page isn't already open, open the console left side menu and select APIs & services, and then select Library.
  4. Click the API you want to enable. ...
  5. Click ENABLE.

How do I use a JSON API? ›

Using JSON API From Client Applications

Client application must send POST requests to JSON web service endpoint URL. The requests should contain a JSON object in their body or in the POST variable named "json". For multipart requests the JSON object must be either in a "json" string part or in a "json" query parameter.

How to use JSON data from an API? ›

Using JSON in API calls

parse() to start using it. JSON. parse(string) takes a string of valid JSON and returns a JavaScript object. For example, it can be called on the body of an API response to give you a usable object.

Top Articles
Latest Posts
Article information

Author: Rev. Leonie Wyman

Last Updated:

Views: 5426

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Rev. Leonie Wyman

Birthday: 1993-07-01

Address: Suite 763 6272 Lang Bypass, New Xochitlport, VT 72704-3308

Phone: +22014484519944

Job: Banking Officer

Hobby: Sailing, Gaming, Basketball, Calligraphy, Mycology, Astronomy, Juggling

Introduction: My name is Rev. Leonie Wyman, I am a colorful, tasty, splendid, fair, witty, gorgeous, splendid person who loves writing and wants to share my knowledge and understanding with you.