top of page

How to Integrate Wix with Google Sheets: Secure Backend Example

Writer: Faysal Jaali
Faysal Jaali
Aug 2, 2023
6 min read

Updated: Nov 2

To integrate Wix with a private Google Sheet, keep authentication on the backend and return only the data the caller is allowed to see. A service-account JSON key is not itself an OAuth bearer access token.


This walkthrough reads a fixed catalog range for an administrator. It deliberately starts with a small read-only workflow so authentication and data permissions can be checked before building a public feature.


how to integrate wix with google sheets
Google Sheets, used as the private data source in this integration example.

Prepare the Google and Wix settings


Enable the Google Sheets API in the Google Cloud project. Create an appropriate service account and share the specific spreadsheet with its service-account email address as a viewer. Review your organization’s policy before creating a downloadable key.


Store the service-account JSON as GOOGLE_SERVICE_ACCOUNT_JSON in Wix Secrets Manager. Use only credentials generated for your own project. Add the google-auth-library package through your Wix development environment’s supported npm workflow.


Google’s server-to-server authorization guide explains how credentials are used to obtain access tokens. Its Node.js authentication library handles authenticated requests, rather than requiring a manually copied access token.


Read a fixed range through a backend web method


Create backend/sheets.web.js. Replace the spreadsheet ID and change Catalog!A2:C20 to your sheet’s actual tab and range. The example expects name, category and display price in the first three selected columns.


// backend/sheets.web.js
import { webMethod, Permissions } from "@wix/web-methods";
import { secrets } from "@wix/secrets";
import { auth } from "@wix/essentials";
import { GoogleAuth } from "google-auth-library";

const readSecret = auth.elevate(secrets.getSecretValue);
const spreadsheetId = "REPLACE_WITH_YOUR_SPREADSHEET_ID";
const range = "Catalog!A2:C20";

export const readCatalog = webMethod(Permissions.Admin, async () => {
  try {
    const { value } = await readSecret("GOOGLE_SERVICE_ACCOUNT_JSON");
    const credentials = JSON.parse(value);
    if (
      credentials.type !== "service_account" ||
      typeof credentials.client_email !== "string" ||
      typeof credentials.private_key !== "string"
    ) {
      throw new Error("Invalid service-account configuration");
    }
    const googleAuth = new GoogleAuth({
      credentials,
      scopes: ["https://www.googleapis.com/auth/spreadsheets.readonly"]
    });
    const client = await googleAuth.getClient();
    const url =
      "https://sheets.googleapis.com/v4/spreadsheets/" +
      encodeURIComponent(spreadsheetId) +
      "/values/" + encodeURIComponent(range);
    const response = await client.request({ url });
    const rows = response.data.values ?? [];
    if (!Array.isArray(rows) || !rows.every(Array.isArray)) {
      throw new Error("Unexpected sheet response");
    }
    return rows.map(row => ({
      name: String(row[0] ?? ""),
      category: String(row[1] ?? ""),
      displayPrice: String(row[2] ?? "")
    }));
  } catch {
    throw new Error("The catalog could not be loaded. Check backend configuration.");
  }
});

The read-only scope restricts the type of API access, while sharing the spreadsheet grants the service account access to that file. These are separate checks.


The Sheets values.get reference documents the spreadsheet ID, A1 range and returned values. Missing trailing cells can be omitted from that response, which is why the mapping supplies empty strings.


Call it as an administrator


From an appropriate admin-only test page, import readCatalog from backend/sheets.web and await readCatalog(). Review the returned fields before connecting them to a repeater or table.


The Wix web-method documentation explains permission levels. This method is restricted to site administrators; an ordinary visitor should be denied.


If you later publish a public catalog, create a separate method that exposes only approved public fields. Keep the spreadsheet ID and range controlled by the backend. Do not let visitors request arbitrary sheets, ranges or credentials.


Avoid common authentication mistakes


Do not place the private key in frontend code or send the complete credential JSON as an Authorization header. Do not ask an editor to paste a temporary access token into the article’s code and expect permanent access.


If you encounter an authorization error, check the project API configuration, the service-account identity, file sharing and scope separately. Keep private keys and raw provider errors out of browser messages and logs.


Reading is not real-time synchronization


This example reads when invoked. Editing the sheet does not automatically push a live update to every open browser.


Define how fresh the displayed information must be, then choose an appropriate refresh, cache or synchronization process. For order-critical information, use a workflow with explicit validation rather than treating a spreadsheet display as an inventory guarantee.


Prepare a small sheet before connecting the website


Create a test spreadsheet with a tab named Catalog if you intend to use the range shown in the code. Put descriptive column headings in the first row and a few sample records below them. The example reads A2:C20, so its mapping expects the first three selected columns to contain a name, category and display price.


For example, a sample row could contain “Consultation,” “Services” and “Contact us.” These values are illustrative content, not a pricing rule. The backend returns displayPrice as text; it does not validate a payment amount or make a purchase decision.


Keep the initial test range small. Confirm that the expected records appear before adding pagination, filtering or a more complicated data model. A short, known data set makes authentication and mapping errors easier to distinguish.


Configure the service account and share the correct file


Use the Google Cloud project intended for the integration and enable the required Sheets API. Create the appropriate service-account credentials for the server-side workflow. Google’s service-account documentation explains this application identity and the authorization flow.


Share the intended spreadsheet with the service account’s client_email and grant only the access required by the example. A read-only catalog does not need editor access to the file. Sharing the spreadsheet with your personal account alone does not give the service account access.


Store the complete credential JSON in the Wix secret named GOOGLE_SERVICE_ACCOUNT_JSON. Keep it out of page code, screenshots and public CMS content. Preserve the JSON formatting and the private-key value exactly as supplied by the authorized credential download; do not replace escaped newline characters by editing the surrounding JSON arbitrarily.


Set the spreadsheetId constant to the file’s actual identifier and confirm the range constant matches the tab and cells you prepared. The file identifier and the tab name are different values. Install the google-auth-library dependency through the site’s supported package workflow before testing the backend import.


Read the example’s output contract


The readCatalog method returns an array of objects containing name, category and displayPrice. It deliberately selects and converts those three fields instead of returning the entire service response. The page should render those fields as text in the intended elements.


Rows can have missing trailing cells, so the mapping supplies empty strings where values are absent. Decide how the interface should display an incomplete record. For a public catalog, an empty name might be a reason to omit the row rather than show an unexplained blank card.


Keep the sheet’s column order stable or update the mapping when it changes. Adding a new first column without changing the code would make every mapped field refer to the wrong value. Record the agreed column layout with the integration instructions.


Connect the administrator test in stages


First call readCatalog in the controlled administrator workflow described above and inspect whether it returns the known sample records. Then connect those values to the intended page display. Keep the test separate from a visitor-facing endpoint while confirming that the permission boundary and data selection are correct.


Show a clear loading state and an empty state. A successful response with no rows is different from a failed request. Avoid displaying raw service errors or credential details to a visitor. The sample’s backend error message is intentionally general; use authorized backend diagnostics to investigate configuration failures.


For a visitor-facing version, define exactly which records may be public and what request parameters are allowed. Do not expose an arbitrary spreadsheet ID or range supplied by the browser. Keep private contacts, internal notes and unpublished prices out of the returned data.


Troubleshoot the layer that failed


If the credential JSON cannot be parsed, check the stored secret and its format. If the service account cannot access the file, check sharing and the file identifier. If the API request succeeds but returns the wrong records, check the tab, range and column mapping. If the records are correct in the backend but wrong on the page, inspect the display mapping.


Use the official Sheets values.get reference when extending the read behavior. Adding write-back, live synchronization or user-specific spreadsheets requires a separately designed permission and conflict-handling workflow. The read-only example should remain easy to understand before those features are added.


Troubleshooting by integration layer


Observation

First check

Expected result

Credential parsing fails

Complete JSON in the named Wix secret

A service-account object with client_email and private_key

Permission denied

Share the specific sheet with client_email

Read access to the intended file

No expected rows

Spreadsheet ID, Catalog tab and A2:C20

At most 19 selected rows and three mapped columns

Fields are shifted

Column order in the sheet

A → name; B → category; C → displayPrice

Rows load but page stays empty

Page display mapping and empty states

Returned objects shown as text in the intended controls


A2:C20 selects 19 rows across three columns: at most 57 cells. This is range arithmetic, not an API quota. For an intentionally submitted-data workflow, see the triggered-email setup guide.


What was checked?


The example’s request construction, restricted permission, credential handling and row mapping were tested locally with simulated services. Authentication against your private spreadsheet must still be verified with your own configured account.


Can it write to Google Sheets?


This example is read-only. Writing requires a separately designed method, appropriate scopes and validation of the exact permitted operation.


For related workflows, see triggered email setup or contact CodeMasters with your integration requirements.

bottom of page