← All guides

How do I fix CORS errors with the Google Sheets API?

Quick answer

The Google Sheets API does not support CORS for browser requests — it's designed for server-to-server calls. SheetZAPI solves this: connect your sheet, configure your allowed origins in the dashboard, and your frontend can call SheetZAPI's endpoints directly from the browser. No server proxy required.

Why Google Sheets API has CORS errors

The Google Sheets API (sheets.googleapis.com) does not send Access-Control-Allow-Origin headers for browser requests. When your frontend JavaScript tries to fetch from it, the browser blocks the request with a CORS error. The API is designed for server-side use with OAuth tokens — not for direct browser calls. The workaround is typically to proxy through your own backend, which adds infrastructure complexity.

How SheetZAPI enables CORS for browser apps

SheetZAPI's API sits between your browser and Google Sheets. On Developer plans and above, you configure a list of allowed origins in the sheet's settings (e.g., https://yourapp.com). SheetZAPI adds the appropriate Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers response headers. Your frontend fetch() calls work without a server proxy.

Securing browser-accessible endpoints

Even with CORS enabled, every SheetZAPI request requires an API key in the X-API-Key header. For purely public read-only data, you can also use the SheetZAPI embed widget (a JavaScript snippet) which handles authentication automatically and does not expose your API key in frontend code. For write-capable endpoints, always proxy through your backend rather than exposing write-capable keys in the browser.

CORS configuration options

In the sheet settings, specify: allowed origins (comma-separated list or * for any origin), allowed methods (GET only for read-only, or GET + POST + PATCH + DELETE for full access), and whether to allow credentials. Changes take effect immediately without redeployment. You can update allowed origins at any time without changing your API key or endpoint URL.

Frequently asked questions

Why does the Google Sheets API have CORS errors?

The Google Sheets API does not send CORS headers because it's designed for server-side OAuth use, not direct browser calls. Use SheetZAPI to add configurable CORS headers to your sheet's REST endpoints.

How do I call Google Sheets from the browser without CORS errors?

Connect your sheet to SheetZAPI and configure your allowed origins in the dashboard. SheetZAPI adds CORS headers so your frontend JavaScript can fetch directly without a server proxy.

Is it safe to call a Google Sheets API from the browser?

With SheetZAPI, read-only endpoints are safe to call from the browser with CORS enabled — use the embed widget to avoid exposing API keys. For write operations, always proxy through your backend.

Can I restrict which domains call my SheetZAPI endpoint?

Yes. Configure allowed origins in your sheet settings. Only requests from those origins will receive the CORS headers. All other origins will be blocked at the browser level.

Fix your Google Sheets CORS errors with SheetZAPI

Get Started Free