Developers ·

How to Set Up a Google Sheets API Key & Authentication for B2B SaaS

Kunal Mishra
7 min read
Table of Contents

Setting up a Google Sheets API key requires choosing between three distinct credential models to access customer spreadsheet data. This guide helps engineers at B2B SaaS companies evaluate API keys, service accounts, and standard OAuth 2.0 flows. You will find step-by-step Google Cloud Console configuration steps, specific API scopes, and the exact error limits your application must handle in production environments. Choosing the correct approach prevents over-scoping customer data and avoids connection timeouts. Before writing authorization code, review the pros, cons, and use cases of common API authentication protocols.

Key Takeaways

  • API keys work only for public, read-only spreadsheet access.
  • Service accounts run background jobs for internal applications.
  • OAuth 2.0 provides delegated access to a specific user’s private spreadsheet data.
  • The read quota enforces a strict limit of 300 requests per minute per project.

Choosing Your Google Sheets API Authentication Method

You must select an authentication method based on data ownership and privacy requirements. An API key works for public sheets in read-only mode. It bypasses user consent screens entirely. If the application processes private data, you need either a service account or an OAuth flow.

A Google Sheets service account allows background jobs to manipulate files owned by the application. Service accounts cannot read a customer’s private sheet unless the customer explicitly shares their document with the service account’s email address.

For customer-facing SaaS products, use a standard OAuth 2.0 flow. Your customer doesn’t configure anything by hand: they are prompted to connect their Google account and approve the requested scopes, and your backend completes the authorization to obtain an access token. This approach securely links your B2B integration to the customer’s Google Workspace identity.

Google Sheets API Authentication Decision TreeYesNoYesNo, app owns dataStart: Accessing SheetsDataIs data public?API KeyRequires user consent?OAuth 2.0Service Account

Step-by-Step Google Cloud Console Setup

All Google Sheets API credentials originate from a centralized Google Developer Project. Follow this step-by-step setup in Google Cloud Console to establish a baseline connection. You must configure the project before making any programmatic requests.

Google Cloud Console Setup Checklist:

  • Create a new Google Developer Project.
  • Navigate to the API Library and enable the Google Sheets API.
  • Configure the OAuth consent screen with your application name and privacy policy URL.
  • Navigate to the Credentials tab to generate your specific keys.

To query public data, learn how to get a Google Sheets API key by selecting "Create Credentials" and choosing "API Key". You must restrict this key to your application’s domain or IP address to prevent quota theft.

With Knit: This guide walks you through creating your own Google OAuth App in Google Cloud Console so your users will see your brand and logo when integrating Gmail with Knit.

For server-to-server interactions, generate a JSON file containing the service account private key. Store this file securely in a secrets manager. If you are building a user-facing integration, create OAuth 2.0 Client IDs to generate your Client ID and Client Secret values.

Configuring Required Google Sheets API Scopes

Scopes define the exact boundaries of your application’s access to user data. Check scopes and endpoints against Google’s documentation before adding them to your application code. Requesting broad permissions often causes enterprise security teams to block the integration entirely.

The exact scope required to see, edit, create, and delete all your Google Sheets spreadsheets is https://www.googleapis.com/auth/spreadsheets, according to Google for Developers. Use this scope only if the product directly writes data back to the user’s files. For example, a marketing application exporting campaign metrics to a user’s drive requires this full-access permission.

The read-only scope required to see all your Google Sheets spreadsheets is https://www.googleapis.com/auth/spreadsheets.readonly. Applying this restricted scope accelerates security reviews. Many B2B integrations only need to ingest reporting data, making the read-only scope the safest default configuration.

Implementing OAuth 2.0 for Your B2B Integration

Standard Google Sheets OAuth requires directing users to a Google-hosted consent screen. Once the user approves the requested scopes, the authorization server returns a code to your callback URL. Your backend exchanges this code for an access token and a refresh token.

According to Google for Developers, access tokens are issued by the Google OAuth 2.0 Authorization Server. You must store the long-lived refresh token in your database to request new access tokens automatically.

Authentication is managed by adding an Authorization header with a bearer token to each API request. The base URL is always https://sheets.googleapis.com/v4/. Use the default header format Authorization: Bearer <access_token> to fetch sheet data. You face similar token management requirements when you call the GitHub API or query CRM object endpoints alongside spreadsheet data. Normalizing these token lifecycles requires structured token storage.

How to Register Credentials with Knit

Knit standardizes the OAuth credential management process across multiple integrations. You map the application directly to the Knit hub at /integration/google-sheets/.

You can register your application’s credentials directly via Knit using the Client OAuth Credentials API. Send a POST request to https://api.getknit.dev/v1.0/integration.registerOauthCreds. Include the required headers Authorization: Bearer <YOUR_KNIT_API_KEY> and X-Knit-Integration-Id: <...>. Pass the appId, clientId, and clientSecret in the JSON request body. The endpoint responds with success and data fields.

Alternatively, use the Register OAuth Credentials API by sending a POST to https://api.getknit.dev/v1.0/oauth.creds.register. This endpoint accepts additional configuration fields including originOrgId, tokenUrl, authUrl, scopes, and metaData. Knit supports mapping these credentials to apps like Google Calendar (app ID google-calendar).

Troubleshooting Google Sheets API Auth Errors and Rate Limits

Production environments encounter specific Google Sheets API authentication errors related to token expiry and permissions. Common errors include 401 and 403 HTTP statuses. A 401 Unauthorized response indicates an expired access token or a missing authorization header. A 403 Forbidden response occurs when the authenticated identity lacks permission to view the specific file ID requested.

The API enforces strict usage caps to maintain service stability. According to the Google for Developers documentation, there is a read request limit of 300 per minute per project.

If your app sends 350 requests in one minute, the additional 50 requests exceed the quota and generate a 429: Too many requests HTTP status code response. You must implement exponential backoff logic to retry these specific failures. Handling these rate constraints mirrors the logic required to query core management endpoints or call the Jira REST API, where each platform dictates its own specific rate limit thresholds.

Frequently Asked Questions

How do I get a Google Sheets API key, and is it secure enough for my use case?

You generate a Google Sheets API key in the Google Cloud Console by navigating to APIs & Services, clicking Credentials, and selecting Create Credentials. It is only secure for reading publicly visible data. API keys do not identify individual users or grant access to private files.

When should I use OAuth 2.0 instead of a service account or basic API key?

Use OAuth 2.0 when your application must read or write data on behalf of an individual user. Service accounts fit automated, server-to-server tasks where the application owns the document. API keys fit purely public data retrieval.

What are the exact steps to create Google Sheets credentials in Google Cloud Console?

Create a Google Developer Project and enable the Sheets API in the library. Navigate to the Credentials tab, configure the OAuth consent screen, and click Create Credentials. Select your desired credential type based on your authentication strategy.

Which specific scopes do I need to request to read and write to a user’s sheet?

You need the exact scope https://www.googleapis.com/auth/spreadsheets to see, edit, create, and delete spreadsheets. Use the read-only variant https://www.googleapis.com/auth/spreadsheets.readonly if you only need to view data.

Why am I getting 401 Unauthorized or 403 Forbidden errors when connecting to the API?

A 401 error means your access token expired or the authorization header is malformed. A 403 error means your authentication succeeded, but the specific identity lacks sharing permissions for the requested spreadsheet file. Review your token refresh logic and confirm the document is shared with the authenticated email address to resolve these connection failures.

Written by Kunal Mishra

Changing integration landscape, one organization at a time‍

Keep Reading

#1 in Ease of Integrations

4.9 out of 5 stars

4.9 out of 5 stars on G2

G2 Leader, Spring 2026G2 Fastest Implementation, Spring 2026G2 High Performer, Spring 2026G2 Best Est. ROI, Spring 2026

Put Integrations on Autopilot. Talk to Experts.

Knit is loved by customers across the globe due to our seamless product and white glove support. You'll love us too!

Talk to a Human