You cannot create a plain "Google Sheets API key" that reads or writes your spreadsheets. Google Sheets data is private, so the Sheets API requires OAuth 2.0 credentials (a service account or a user consent flow), not a simple API key. An API key only unlocks public, read-only Google APIs like Maps or YouTube search — it will not authenticate a request to the Sheets API. What you can do is create a Google Cloud project, enable the Sheets API, and generate either a service account key (a JSON file) or OAuth client credentials. That JSON file is what most people mean when they say "Sheets API key."
What You'll Need
- A Google account (a personal Gmail account works, but a Workspace account gives you more control over sharing).
- Access to the Google Cloud Console at console.cloud.google.com.
- A spreadsheet you own or can edit, and the email address of the service account you will share it with.
- If you are scripting: a tool that can make HTTPS requests (Python, Node.js, Google Apps Script, Postman, curl).
- For Apps Script specifically, you do not need any of this — see the note in Tips.
Step-by-Step
- Create or select a Google Cloud project. Go to console.cloud.google.com and sign in. Use the project selector at the top of the page to create a new project or pick an existing one. Give it a recognizable name like "Sheets Integration."
- Enable the Google Sheets API. In the left navigation, open APIs & Services > Library. Search for "Google Sheets API," open the result, and click Enable. If you also plan to create files programmatically, enable the Google Drive API the same way. Menu labels can differ slightly by console version and region, but the Library path is stable.
- Decide which credential type you need. For a server or script acting on its own behalf (no human login), use a service account. For an app where a real user signs in and grants access to their own spreadsheets, use OAuth client ID. The rest of these steps cover the service account, which is the closest thing to a "Sheets API key."
- Create a service account. Go to APIs & Services > Credentials, click Create credentials, and choose Service account. Enter a name and description, then click Create and continue. You can skip the optional role and user-access steps — the spreadsheet sharing in step 6 is what actually grants access.
- Download the JSON key. On the Credentials page, click the service account you just made, open the Keys tab, click Add key > Create new key, choose JSON, and click Create. A JSON file downloads automatically. Treat this file like a password: anyone who has it can act as that service account. Store it outside your code repository and never commit it to Git.
- Share the spreadsheet with the service account. Open the JSON file and find the
client_emailvalue — it looks likename@project-id.iam.gserviceaccount.com. Open your Google Sheet, click Share, paste that email, choose Editor (or Viewer for read-only), and send. Without this step every request returns a 403 permission error. - Make an authenticated request. Your code must sign a JWT with the private key from the JSON file, exchange it for an access token at Google's OAuth token endpoint, then call the Sheets API with
Authorization: Bearer <token>. In Python, the officialgoogle-api-python-clientandgoogle-authlibraries handle this: build credentials from the service account file with the Sheets read/write scope, then callspreadsheets().values().get()with your spreadsheet ID. The spreadsheet ID is the long string in the sheet URL between/d/and/edit. - Test with a read call first. Read a small range such as
Sheet1!A1:C5before attempting writes. If the read succeeds, your credentials, scopes, and sharing are all correct, and any later write failure is a permissions or range problem rather than an auth problem.
Common Mistakes
The most frequent error is trying to pass an API key to the Sheets API. It will be rejected because the API requires OAuth. Creating an API key under Credentials is fine for other Google APIs, but it does nothing for Sheets.
Second: forgetting to share the spreadsheet with the service account email. The service account is a separate identity with its own Drive, so a sheet in your Drive is invisible to it until you share it explicitly.
Third: requesting the wrong scope. Read-only calls fail with a 403 if the code requests only a read scope but then tries to write, or if the account was shared as Viewer but the code attempts an update. Match the scope to the sharing level.
Fourth: leaking the JSON key. Committing it to a public repo is a real security incident — rotate the key immediately in the Cloud Console if it happens.
Tips
- If your script runs inside Google's ecosystem, use Google Apps Script instead.
SpreadsheetAppneeds no Cloud project, no key, and no sharing step, because it runs as your own account. - Use a separate service account per integration so you can revoke one without breaking the others.
- Store the JSON contents in an environment variable or a secrets manager rather than on disk in production.
- Batch reads and writes with the
batchGetandbatchUpdatemethods to stay well under per-minute quota limits. - Restrict the service account's access to only the sheets it needs — a dedicated folder shared with it is cleaner than sharing your whole Drive.
Troubleshooting
403 "The caller does not have permission." The sheet is not shared with the service account email, or it was shared with the wrong address. Recheck the client_email in the JSON file against the Share dialog.
403 "Request had insufficient authentication scopes." Your code requested a narrower scope than the operation needs. Regenerate credentials with the read/write Sheets scope.
400 "Unable to parse range." The sheet tab name is wrong or missing. Include the tab name exactly, and wrap names containing spaces in single quotes, e.g. 'My Sheet'!A1:B2.
401 invalid_grant or invalid JWT. The system clock on the machine making the request is likely off, or the key was deleted. Check the time sync, then confirm the key still exists under the service account's Keys tab.
API not enabled. A 403 mentioning "has not been used in project" means you enabled the API in a different project than the one the credentials belong to. Enable it in the project shown in the JSON file's project_id.
If none of that resolves it, create a fresh JSON key, share the sheet again with the new email, and retry a simple read. Rotating the key is safe; just delete the old one afterward in the Cloud Console.
Frequently Asked Questions
Can I use a simple API key with Google Sheets?
No. The Sheets API requires OAuth 2.0. API keys are only for public, read-only APIs that do not touch private user data.
Is a service account key the same as an API key?
No, but it is the closest equivalent. It is a JSON file containing a private key that your code uses to obtain short-lived access tokens.
Do I need to share the spreadsheet with the service account?
Yes. The service account is its own identity. Until you share the file with its email address, it has no access.
Can I use this from Google Apps Script?
You do not need to. Apps Script's built-in SpreadsheetApp service runs as your account and requires no Cloud credentials.
How do I find my spreadsheet ID?
Open the sheet and look at the URL. The ID is the long string between /d/ and /edit.
What should I do if my JSON key leaks?
Delete that key in the Cloud Console immediately, create a replacement, and update your code. The old key stops working as soon as it is deleted.