Sync from Google Sheets

Keep your stores in a Google Sheet, and a sync task imports them on a schedule. You need a Google Sheets API key and a sheet that anyone with the link can view. This guide is part of Data Sync; for the add-on itself, see Import & Sync.

Not ready for an API key? Publish the sheet as a CSV file and use the CSV URL source instead.

Create the API Key

The sheet is read by your web server, not by a visitor’s browser. Use a separate key from the one that shows your map: that one is usually restricted to your website, and such a key doesn’t work from a server.

  1. Open the Google Cloud console and pick a project, or create one.
  2. Go to APIs & Services > Library, search for Google Sheets API and click Enable.
  3. Go to APIs & Services > Credentials, and choose Create credentials > API key from the menu at the top of the page. Copy the key.
    Don’t use the Create credentials button on the Google Sheets API page: it opens a wizard that asks “What data will you be accessing?”, and neither answer makes an API key.
  4. Click the key’s name to restrict it:
    • API restrictions: choose Restrict key and tick only Google Sheets API.
    • Application restrictions: choose None, or IP addresses with your web server’s outgoing IP address. Don’t choose Websites: the request comes from your server, so a website restriction blocks it.
  5. Click Save. A new key, or a change to its restrictions, can take up to five minutes to work.

An API key only reads sheets shared with “Anyone with the link”. It can’t read private sheets.

Share the Sheet

  1. Open the sheet and click Share.
  2. Under General access, choose Anyone with the link, with the role Viewer. In Google Workspace, choose “Anyone with the link”, not “Anyone at your company with the link”.
  3. Copy the sheet’s address from the browser bar, for example https://docs.google.com/spreadsheets/d/1AbC…xyz/edit#gid=0.

Put one store on each row, and the column names ( Name, Address, City and so on ) in the first row. Sharing changes work right away.

Fill in the Connect Step

Start a new sync task, choose Google Sheets and fill in:

The Connect step for Google Sheets, with the API Key, Spreadsheet URL, Sheet Name and Header Row fields
Field What to enter
Name Any name, for example “Dealers sheet”. It’s shown in the task list and the email reports.
API Key The key you created. See One Key for the Whole Site below.
Spreadsheet URL The full address of the sheet. The spreadsheet ID is taken from it.
Sheet Name Leave it empty to use the first tab. Only fill it in to read another tab, with the name exactly as it is on the tab.
Header Row The row with the column names. Defaults to 1. Change it when the sheet has a title or notes above the column names.

One Key for the Whole Site

When you save a task after a successful test, its API key is saved for the site, and every Google Sheets task uses it. On your next Google Sheets task the API Key field already says “Saved, ends in …”: leave it empty to use that key, or enter a new one to replace it. The key is stored encrypted.

Next to a saved key, Show shows it and Remove removes it. Before you remove it, the dialog says how many sync tasks use the key: they stop working until they get a key again.

Test It

Click Test connection. It says how many rows it found, such as “Connected. 24 rows found.”, and the columns of the sheet appear on the next step, Map fields. If it fails, the message says why and what to do. The most common ones are below.

Does your sheet have a column with a store number or ID? Map it to External ID, so a store you rename in the sheet is still found ( see The ID Columns ).

Troubleshooting

The API key and the sheet are checked separately: a working key still can’t read a sheet that isn’t shared.

Message after Test connection What to do
Google Sheets cannot open this sheet because it is not shared publicly. In the sheet, click Share and set General access to Anyone with the link, role Viewer. In Google Workspace, not “Anyone at your company with the link”.
This API key only works on certain websites. In Google Cloud, set the key’s application restriction to None, or to IP addresses with your server’s IP address.
This API key only works from certain IP addresses, and the address of this server is not one of them. Add your web server’s outgoing IP address to the key’s IP restriction. Your host can tell you the address.
The Google Sheets API is not enabled for this API key. Click the Google Sheets API page link in the message, click Enable, and wait a few minutes.
This API key may not use the Google Sheets API. Add Google Sheets API to the key’s API restrictions.
The API key is not valid. Copy the key again from the credentials page the message links to.
This spreadsheet has no tab called “…”. Leave Sheet Name empty to use the first tab, or enter the name exactly as it is on the tab.
The first tab of the spreadsheet has no column names in row 1. If the stores are on another tab, enter its name under Sheet Name. If the column names are on another row, change Header Row.
Google found no spreadsheet at this Spreadsheet URL. Copy the address of the sheet again.
The Spreadsheet URL was not saved: paste the address of the Google Sheet, https://docs.google.com/spreadsheets/d/… The address isn’t the address of a Google Sheet. Copy it from the browser bar while the sheet is open.
The sheet (…) is too large to read with the memory PHP may use on this site (…). Split the stores over two sheets, each with its own sync task, or ask your host to raise PHP’s memory limit.

For some errors Google’s own words follow on a line of their own, for example “Google Sheets error 403: …”. Mention them when you contact support.

Next