CSE Search

Query Google Custom Search Engines in Google Sheets

ongoing since google sheets tagJavaScript tag Google Workspace Marketplace

Update 2024-11-11

As of January 8, 2025, Google is retiring the Custom Search Site Restricted JSON API endpoints. Custom Search Engines where ‘Search the entire web’ is set to ON will continue to work subject to daily limits. You will need to update your search engines or you could look into how to migrate to Google’s Vertex API.

Description

Three custom functions that output a 2D array of results from a Google custom search engines. Return web results and images.

How To Use

Set-up

  1. Go to the CSE Developer Overview and select “Get a Key”.
  2. Select a new or existing project and make a note of the API key.
  3. Go to Google CSE and select an existing search engine or create a new one. For help with this, read the documentation and help center.
  4. Click on ‘Search Engine ID’ and make a note of the code. It will look similar to “12345678900987654321:abcdefghi01”.
  5. Open the API Set-up from the CSE Search Add-on menu and enter the API key from step 2 & Default Search Engine from step 4, then press save. You can now use the CSE functions.

Basic

Enter ‘=CSE()’ in any cell. The parameters for this function are listed below:

Images

Enter ‘=CSE_IMAGE()’ in any cell. The parameters for this function are listed below:

Advanced

Enter ‘=CSE_ADVANCED()’ in any cell. The parameters for this function are listed below:

Output

Both functions output a 2D array of information from the custom search with headers on row one. This can take up a lot of columns, so consider transposing the output. Results are stored in the document to improve performance and minimise the amount of requests made to your search engine, however this is not always possible with large responses.

Examples

To search for one result about a dog enter =CSE(“dog”) in any cell.

To search for ten images of dogs while preferring local results, enter =CSE(“dog”,24,1,10,TRUE) in any cell. While some of these parameters could be omitted, you should use default values to maintain clarity.

Permissions

Here’s what CSE Search does with each of the permissions it requires:

Further details can be found in the GSuite Add-on Privacy Policy.

Uh-oh, Something Broke!

Contact me, giving as much detail as you can.

Changelog​