How to get Google search results into Google Sheets

Checked on 2026-11-24.

Google Sheets has no built-in function that searches Google. The Custom Search JSON API, which Apps Script can call, is closed to new customers and ends on January 1, 2027, and an IMPORTXML formula pointed at google.com/search runs into Google's own rules. For a new sheet, what is left is an HTTP API called from a custom function: the results of a search in rows, or the position of a site for a column of keywords.

1. The Custom Search JSON API, if you already have it

If your Google Cloud project already uses the API, Apps Script can call it. Google's REST page asks for three things: the API key (key), the Programmable Search Engine to use (cx) and the search (q). Store the first two as script properties named GOOGLE_API_KEY and GOOGLE_SEARCH_ENGINE_ID, the way the key is stored further down.

JavaScript
/**
 * Title, link and snippet of each result, from the Custom Search JSON API.
 * @customfunction
 */
function CSE_RESULTS(query) {
  if (!query) return "";
  const props = PropertiesService.getScriptProperties();
  const url = "https://www.googleapis.com/customsearch/v1"
    + "?key=" + props.getProperty("GOOGLE_API_KEY")
    + "&cx=" + props.getProperty("GOOGLE_SEARCH_ENGINE_ID")
    + "&q=" + encodeURIComponent(query);
  const body = JSON.parse(UrlFetchApp.fetch(url, { muteHttpExceptions: true }).getContentText());
  if (body.error) throw new Error(body.error.message);
  if (!body.items) return "No results";
  return body.items.map((item) => [item.title, item.link, item.snippet]);
}

One request returns at most 10 results (the reference gives num as "integers between 1 and 10"), and the API "returns up to the first 100 results only". The overview gives the price: "100 search queries per day for free", then "$5 per 1000 queries, up to 10k queries per day".

Where it stops: the same overview says "The Custom Search JSON API is closed to new customers" and "Existing Custom Search JSON API customers have until January 1, 2027 to transition to an alternative solution." It names two: Vertex AI Search, "a favorable alternative for searching up to 50 domains", and a "full web search solution" you ask about through a contact form. A sheet built on this function stops working on that date at the latest.

Why not IMPORTXML on google.com?

Three things Google publishes stand against an IMPORTXML formula with a google.com/search address. Its robots.txt has Disallow: /search for all crawlers. Its Terms of Service, effective July 30, 2026, rule out "using automated means to access content from any of our services in violation of the machine-readable instructions on our web pages (for example, robots.txt files that disallow crawling, training, or other activities)". And its spam policies define machine-generated traffic as "sending automated queries to Google", which "includes scraping results for rank-checking purposes or other types of automated access to Google Search conducted without express permission". What google.com/search sends back to IMPORTXML is not documented either, so this guide shows no such formula.

2. A custom function for results and positions

The Pipefetch Google search endpoint returns the first page of Google results for a search as JSON. In your sheet open Extensions, then Apps Script, delete what is in the editor, paste this and click Save.

JavaScript
const API = "https://pipefetch.com";

// One request to the API. A 404 means nothing was found, which costs nothing.
function pipefetch_(path, params) {
  const key = PropertiesService.getScriptProperties().getProperty("PIPEFETCH_API_KEY");
  if (!key) throw new Error("Add PIPEFETCH_API_KEY under Project Settings, Script properties.");
  const query = Object.keys(params).map((name) => name + "=" + encodeURIComponent(params[name])).join("&");
  const res = UrlFetchApp.fetch(API + path + "?" + query, {
    headers: { "x-api-key": key },
    muteHttpExceptions: true,
  });
  if (res.getResponseCode() === 404) return null;
  const body = JSON.parse(res.getContentText());
  if (res.getResponseCode() !== 200) throw new Error(body.error.message);
  return body.data;
}

/**
 * The first page of Google results: position, title, address and snippet, one result per row.
 * @customfunction
 */
function GOOGLE_RESULTS(query, country) {
  if (!query) return "";
  const params = { q: query };
  if (country) params.country = country;
  const data = pipefetch_("/v1/google/search", params);
  if (!data) return "No results";
  return data.results.map((r) => [r.position, r.title, r.url, r.description || ""]);
}

/**
 * Where the first result from a domain (or its subdomains) ranks on page one.
 * @customfunction
 */
function GOOGLE_POSITION(query, domain, country) {
  if (!query || !domain) return "";
  const params = { q: query };
  if (country) params.country = country;
  const data = pipefetch_("/v1/google/search", params);
  if (!data) return "No results";
  const hit = data.results.find((r) => r.domain === domain || String(r.domain).endsWith("." + domain));
  return hit ? hit.position : "Not on page 1";
}

Store your API key

Keep the key out of the script and out of the cells. In the Apps Script editor click Project Settings, and under Script Properties click Add script property: the name is PIPEFETCH_API_KEY, the value your key. You get a key, with 100 free credits and no card, in the dashboard. Editors of the sheet "can view, edit, and run its bound script", in the words of Google's page on bound scripts, so they can read the key too; share results with anyone else as values in a sheet without the script.

Use the functions

Terminal
=GOOGLE_RESULTS(A2)                  position, title, address and snippet, one result per row
=GOOGLE_RESULTS(A2, "GB")            the same search in Google's results for the United Kingdom
=GOOGLE_POSITION(A2, "zapier.com")   where zapier.com first appears on page one

GOOGLE_RESULTS fills about ten rows and four columns, so give each search its own block or tab. For a column of keywords use GOOGLE_POSITION: one cell per keyword, "Not on page 1" when the site is not there, and a result counts as the site's when its domain is the one you give, written bare like zapier.com, or a subdomain of it. In the reference's example answer, "best crm software" on 19 November 2026, zapier.com was second.

Google's operators, such as site: and quoted phrases, work in the search. Without a country the results are Google's for the United States; both functions take a two-letter country code as their last argument. Each search with results costs 1 credit; one without results costs nothing.

Where it stops: one request is the first page, about 10 organic results, with no further pages. Pipefetch reads the light results page Google serves to clients without JavaScript, so ads, AI Overview, People also ask, the featured snippet, the places block, top stories, the knowledge panel, videos and images are not in it. Results are for a country, not a city, and for a visitor who is not signed in, so a position can differ from the one on your screen. Google sometimes refuses a search: the cell shows an error, the request costs nothing, and re-entering the formula tries again. It is not an official Google API, and Pipefetch is not affiliated with Google. The reading happens on Pipefetch's servers, but it is still automated reading of a Google results page, which is what the policies quoted above are about.

The limits that bite

  • 30 seconds per cell. Google's custom functions guide: "A custom function call must return within 30 seconds." Otherwise the cell shows #ERROR! with the note Exceeded maximum execution time (line 0). Most requests take 2 to 9 seconds. A request the cell gave up on can still finish on our side, and if it returns data it is charged although the cell never shows it; one that returns nothing costs nothing.
  • Recalculation is a new request. A custom function runs again when you edit its formula or change a cell it points to, and each run that returns data is charged. To be sure a filled column is never fetched again, paste it over itself with Paste special, Values only. Passing NOW() or RAND() to make it refresh does not work: volatile arguments are not allowed, and the cell shows Loading... indefinitely.
  • Google's daily quota. The quotas page allows 20,000 URL Fetch calls a day for a personal Google account and 100,000 for Google Workspace, reset 24 hours after the first request. Custom functions run as an anonymous user, but the calls count against whoever is at the keyboard.
  • Pipefetch's limits. 120 requests a minute per account; above that the cell shows "Too many requests. Slow down and retry in a moment." Requests that find nothing are free, up to 100 a day plus one for every request that returned data, reset at 00:00 UTC. Every formula is its own search: GOOGLE_RESULTS and GOOGLE_POSITION on the same keyword are two requests.

Hundreds of rows

A long column of formulas runs into Google's limits. "Each time a custom function is used in a spreadsheet, Sheets makes a separate call to the Apps Script server", says its guide, and by the hundred "this process can be slow". The quotas page allows 30 simultaneous executions per user and names two errors that "most commonly" come from custom functions called repeatedly in one spreadsheet: Script invoked too many times per second for this Google user account. and There are too many scripts running simultaneously for this Google user account. Re-entering a failed cell's formula tries again.

Google's remedy, one function over a whole range, does not fit here: that one call still has 30 seconds, and each lookup takes seconds. Its guide names the other way: "To edit arbitrary cells, use a custom menu to run a function instead." A run started from a menu may take 6 minutes. Add this to the same script, save, and reload the sheet:

JavaScript
function onOpen() {
  SpreadsheetApp.getUi().createMenu("Pipefetch")
    .addItem("Fill positions", "fillPositions")
    .addToUi();
}

const DOMAIN = "zapier.com";  // the site whose positions you want

function fillPositions() {
  fillColumn_((keyword) => {
    const data = pipefetch_("/v1/google/search", { q: keyword });
    if (!data) return ["No results", ""];
    const hit = data.results.find((r) => r.domain === DOMAIN || String(r.domain).endsWith("." + DOMAIN));
    return hit ? [hit.position, hit.url] : ["Not on page 1", ""];
  });
}

// Column A holds what to look up, from row 2 down; results go into column B and the columns after it.
// Rows that already have something in column B are skipped, so a second run carries on from there.
function fillColumn_(lookup) {
  const sheet = SpreadsheetApp.getActiveSheet();
  const rows = sheet.getLastRow() - 1;
  if (rows < 1) return;
  const values = sheet.getRange(2, 1, rows, 2).getValues();
  const stopAt = Date.now() + 4 * 60 * 1000;  // Google ends a run after 6 minutes
  for (let i = 0; i < rows && Date.now() < stopAt; i++) {
    const [input, filled] = values[i];
    if (input === "" || filled !== "") continue;
    const row = lookup(input);
    sheet.getRange(i + 2, 2, 1, row.length).setValues([row]);
    SpreadsheetApp.flush();  // write each row at once, so a later failure loses nothing
  }
}

Choose Pipefetch, then Fill positions, on the tab with keywords in column A. The first run asks you to authorize the script, which now edits the sheet and calls an outside address. It sends one request at a time and writes values, so nothing is fetched again later. It skips rows whose column B is filled and starts nothing new after 4 minutes: choose the item again to carry on. If a request fails, the run stops with the API's message and keeps what it wrote.

Set DOMAIN to your site before the first run. It writes the position into column B and the address that ranks into column C.

Which one should you use?

SituationUse
You already call the Custom Search JSON APICSE_RESULTS until January 1, 2027, and plan the move now
Search over your own site or up to 50 domainsVertex AI Search, as Google's notice suggests
First-page results or positions for keywords, todayGOOGLE_RESULTS and GOOGLE_POSITION with Pipefetch
Hundreds of keywordsThe Fill positions menu

For the same question from code, and the other official routes Google points to, see how to get Google search results in Python.

Try it with 100 free credits. No card needed. No scraper to build or maintain. Get an API key or read the docs.

Every source

YouTube

Instagram

Websites

TikTok

Facebook

Threads

LinkedIn

App stores

Steam

X

Pinterest

Airbnb

Real estate

Keywords

Job boards

Eventbrite

Shopify stores

Public tenders

All guides