# How to Use an API in Google Sheets

Three ways to bring API data into a sheet: formulas, Apps Script and an add-on. What each one takes to set up, and when each one breaks.

By Jake Marsh. Updated Nov 29, 2026.

## The short answer

There are three ways to get API data into Google Sheets, and they trade setup time for how much they can handle:

1. **A formula** such as IMPORTDATA or IMPORTXML. Nothing to install, but it only reads public files at an address you can paste. It can't send a key, can't read JSON and can't follow pages.
2. **Apps Script**, Google's scripting for Sheets. Its UrlFetchApp service can call any API with any header, and a time trigger can run it on a schedule. You write and maintain the code.
3. **An add-on** that does the Apps Script part for you: you pick the app or paste the request, the add-on sends it, turns the response into rows and refreshes the tab on a schedule.

Most people start with the first, hit a wall the day an API asks for a key, and then choose between writing code and installing something. The rest of this guide shows what each step involves so you can choose with your eyes open.

## Way 1: a formula

Google Sheets has four import formulas that read from outside the spreadsheet: IMPORTDATA for CSV and TSV files, IMPORTXML for XML, HTML and feeds, IMPORTHTML for a table or list on a web page, and IMPORTFEED for RSS and Atom. Each takes an address and returns rows:

```
=IMPORTDATA("https://example.com/exports/orders.csv")
```

That works when the data is public and already shaped like a table. It stops working the moment an API wants proof of who you are. IMPORTDATA has one argument, the address, so the only place a key can go is inside that address, where everyone the sheet is shared with can read it. And the response has to be CSV or TSV: Sheets has no built-in formula that turns JSON into rows. The [IMPORTDATA, IMPORTXML and IMPORTHTML guide](https://cellfetch.greatwork.company/guides/importdata-importxml-importhtml) covers how often these formulas refresh and the errors people hit with them.

## Way 2: Apps Script and UrlFetchApp

Open **Extensions > Apps Script** in your sheet and you get a JavaScript editor bound to that spreadsheet. UrlFetchApp sends any request: method, headers, body. This is the smallest script that pulls one page of records into a tab called Deals:

```js
function importDeals() {
  const token = PropertiesService.getUserProperties().getProperty('API_TOKEN');
  const res = UrlFetchApp.fetch('https://api.example.com/v1/deals?limit=100', {
    headers: { Authorization: 'Bearer ' + token },
    muteHttpExceptions: true,
  });
  if (res.getResponseCode() !== 200) throw new Error(res.getContentText());
  const deals = JSON.parse(res.getContentText()).data;
  const rows = deals.map((d) => [d.id, d.title, d.value, d.stage]);
  const sh = SpreadsheetApp.getActive().getSheetByName('Deals');
  sh.getRange(2, 1, sh.getMaxRows() - 1, 4).clearContent();
  if (rows.length) sh.getRange(2, 1, rows.length, 4).setValues(rows);
}
```

Three things in it are easy to get wrong:

- **The key lives in user properties**, not in the code. Anyone who can edit the sheet can open its bound script and read a key typed into it. Save it once with `PropertiesService.getUserProperties().setProperty('API_TOKEN', '...')` from the editor and delete that line. Some apps hand out a client ID and secret instead of a key; then the script first trades them for a short-lived token, the OAuth client credentials flow, and repeats that when the token expires.
- **Text that starts with = becomes a formula.** `setValues` treats a string like `=HYPERLINK(...)` as a formula, so a value from the API can run as one in your sheet. Prefix such values with an apostrophe before writing them.
- **It only reads the first page.** Most APIs return 10 to 100 records per request and a pointer to the next page. The [API pagination guide](https://cellfetch.greatwork.company/guides/api-pagination-in-google-sheets) shows the loop that fetches the rest.

To run it on a schedule, add a time-driven trigger (the clock icon in the editor). Apps Script has daily limits on how much of that it does for you: 20,000 URL Fetch calls a day on a personal Google account and 100,000 on Google Workspace, 6 minutes per run, and 90 minutes of trigger time a day on a personal account (6 hours on Workspace). The [refresh guide](https://cellfetch.greatwork.company/guides/refresh-google-sheets-automatically) shows how those add up.

What the script still doesn't do: retry when the API says slow down, convert dates and money into real cell values, keep your report formulas pointed at the right columns, or tell you when it stopped working. Each of those is another afternoon.

## Way 3: an add-on that sends the request for you

An add-on is the same Apps Script machinery packaged for you. In Cellfetch you either pick an app (Stripe, HubSpot, Notion and the others on the integrations page) and paste its key, or build any request by hand: address, method, headers, body, where the records sit in the response, and which values become columns. You can also paste a cURL command from an API's docs and Cellfetch fills in the request, moving any key it finds into a saved connection.

## The parts of an API request

Every API import has the same parts. Here they are for GitHub issues, the way Cellfetch's preset sets them up:

| Part | GitHub |
| --- | --- |
| Method | `GET` |
| Address | `https://api.github.com/repos/{{repo}}/issues` |
| Query | `state=all` |
| Key | `Authorization: Bearer <your token>` |
| Other headers | `Accept: application/vnd.github+json; X-GitHub-Api-Version: 2022-11-28` |
| Pages | `A next-page link in the Link header` |
| Columns | `Number, Title, Type, State and Author and more` |

Keys stay in your own Google account, never in a cell, and Cellfetch sends each one only to the address it belongs to. Pages are followed for you, the tab refreshes on the schedule you pick, and each run writes a line to a Cellfetch log tab so you can see when it ran and what it got.

## Which one to pick

| You need | Formula | Apps Script | Add-on |
|---|---|---|---|
| A public CSV, XML or HTML table | Yes | Yes | Yes |
| An API that wants a key | No | Yes | Yes |
| JSON turned into columns | No | You write it | Built in |
| Every page of a long list | No | You write the loop | Built in |
| Refresh while the sheet is closed | No | With a trigger | Yes, up to hourly |
| Someone else maintains it | Google | You | The add-on's maker |

If the data is a public CSV, use IMPORTDATA and stop there. If you're comfortable keeping a script alive and the API is simple, Apps Script costs nothing but your time. If the sheet feeds a weekly meeting and nobody wants to own code, an add-on is the reasonable choice.

Working with JSON in general, outside any one app? The [import JSON into Google Sheets guide](https://greatwork.company/apps/cellfetch/guides/import-json-into-google-sheets?ref=cellfetch) walks through paths and nested fields. Before you paste a key anywhere, read [API tokens explained](https://cellfetch.greatwork.company/guides/api-tokens-explained) for which kind to create and how to scope it. Terms like bearer token, JSONPath and rate limit have short entries in the glossary.

## Questions

### Does Google Sheets have a built-in way to call an API?

Not one that sends a key. IMPORTDATA, IMPORTXML and IMPORTHTML only take an address, so they work for public CSV, XML and HTML files. Anything that needs an Authorization header, a JSON response turned into rows, or more than one page needs Apps Script or an add-on.

### Can I put my API key in the sheet?

Please don't. A key typed into a cell, a formula or a script bound to the sheet can be read by the people the sheet is shared with. Keep it in user properties (Apps Script) or in an add-on that stores it in your own Google account.

### Why does my script work when I run it but fail on a schedule?

Usually one of three things: the run took longer than Apps Script's 6 minutes, the account ran out of its daily URL Fetch calls (20,000 on a personal account, 100,000 on Google Workspace) or its daily trigger time (90 minutes on a personal account, 6 hours on Workspace), or the key it reads lives in a different user's properties than the one the trigger runs as.

### How do I turn a JSON response into rows?

Find the list of records in the response (for example data, results or items), then pick one value per column. The paths that pick those values are called JSONPath; the glossary entry shows them on a real import.

## More guides

- [API Tokens Explained: Keys, Bearer Tokens and OAuth](https://cellfetch.greatwork.company/guides/api-tokens-explained)
- [API Pagination in Google Sheets](https://cellfetch.greatwork.company/guides/api-pagination-in-google-sheets)
- [How to Refresh Google Sheets Automatically](https://cellfetch.greatwork.company/guides/refresh-google-sheets-automatically)
- [Keep Report Formulas Working When the Data Refreshes](https://cellfetch.greatwork.company/guides/keep-report-formulas-working)

