Google Sheets Sync: Append, Upsert & Dedupe Any Dataset
Pricing
from $0.10 / 1,000 row writtens
Google Sheets Sync: Append, Upsert & Dedupe Any Dataset
Export any Apify dataset or JSON to Google Sheets. Append that really appends, upsert by key, dedupe, auto-added columns, 10M-cell guard and plain-English errors. Works as an integration after any scraper. Uses your own service account.
Pricing
from $0.10 / 1,000 row writtens
Rating
0.0
(0)
Developer
Panthalus
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
16 days ago
Last modified
Categories
Features
Share

Send any Apify dataset or JSON straight into a Google Sheet, reliably. Append rows that really get appended, update existing rows by key (upsert), skip duplicates, and add new columns on the fly. Runs on its own or as an integration after any scraper. It can also read a tab back into a dataset.
It uses your own Google service account, so no third-party app ever gets access to your Google Drive.
What it does
| Mode | What happens |
|---|---|
append | Adds rows under the existing data. Existing rows are never touched. |
replace | Clears the tab and writes the new data. If the input is empty, the tab is left as it is, so an empty scraper run can't wipe your sheet. |
upsert | Rows whose keyColumns match an existing row update that row. Every other row is appended. |
read | Copies a tab into the run's dataset. The header row becomes the field names. |
Options in every write mode: dedupe (skip rows already in the sheet or repeated in this run), columns to export (pick and order the fields), flattening (address.city columns, arrays joined with , ), max rows, rollover to new tabs and dry run (shows what would change and writes nothing).
Why it's reliable
- Append really appends. New rows always go below the last row. Nothing gets overwritten or replaced.
- Upsert by key. You can use one key (
url) or several (sku+store). Only the cells that actually changed are written. Your own formula columns, notes and manual edits in other columns are kept. Unchanged rows are skipped, and you don't pay for them. - Columns are added automatically. The header row is created on the first write. When a later run has new fields, they become new columns at the right. The existing column order is kept, so rows never end up in the wrong columns.
- It checks the 10M-cell limit before writing. Google caps a spreadsheet at 10,000,000 cells, counting all tabs and empty grid cells too. The Actor counts the cells before every write. If the next batch wouldn't fit, it writes the rows that do fit, stops cleanly, and the run summary says how many rows were left out. You don't get a "You reached the max limit" crash halfway through. New tabs are sized exactly, so no cells are wasted.
- Rollover tabs. Set
maxRowsPerTaband data continues in<Tab> (2),<Tab> (3), and so on. Upsert and dedupe search across all of these tabs. - It respects Google's limits. Writes go in batches of up to 1,000 rows (about 2 MB) per request. A client-side rate limiter keeps it under Google's 60 requests per minute per user. Errors 429, 500 and 503 are retried with exponential backoff and jitter, and Google's
Retry-Afterheader is honoured. A write is never retried blindly if Google might already have saved it. - Errors tell you what to do. Examples:
- "The service account can't edit this spreadsheet. In Google Sheets click Share, add sheets-bot@your-project.iam.gserviceaccount.com as Editor..."
- "The Google Sheets API is not enabled in Google Cloud project your-project. Open https://console.cloud.google.com/apis/library/sheets.googleapis.com?project=your-project, click Enable..."
- Wrong spreadsheet ID, an Excel file instead of a Google Sheet, a malformed or deleted key: each has its own plain-English message.
- Safe values. By default text is written as-is (
RAW), so a scraped value like=IMPORTXML(...)is stored as text and never runs as a formula. Integers longer than 15 digits are written as text so no digits are lost. Cells over Google's 50,000-character limit are truncated, and the run reports how many.
Setup: Google service account (about 5 minutes, one time)
- Open https://console.cloud.google.com. In the project picker in the top bar, choose New Project, give it a name, and click Create. You can also use an existing project.
- Go to APIs & Services > Library, search for Google Sheets API, open it and click Enable.
- Go to IAM & Admin > Service Accounts and click + Create service account. Enter a name (e.g.
sheets-sync), then click Create and continue. The service account doesn't need any project role, so you can skip the optional steps. Click Done. - Click the new service account, open the Keys tab and choose Add key > Create new key > JSON > Create. A
.jsonfile downloads. Keep it private. - Open your spreadsheet and click Share. Paste the service account's email (the
client_emailvalue in the JSON file, ending in.iam.gserviceaccount.com), choose Editor, untick Notify people, and click Share. - In this Actor's input, paste the whole content of the JSON file into Service account key (JSON). The field is a secret input, so Apify stores it encrypted.
Tip: run once with Dry run on. It checks the key, the sharing and your data, and shows exactly what would be written.
Use it as an integration after any scraper
- Open the scraper (any Actor or task) in Apify Console and go to its Integrations tab.
- Click Add integration, choose Connect Actor or Task, and pick Google Sheets Sync.
- Fill in the static part of the input: spreadsheet URL, service-account key, tab name, mode (e.g.
upsertwithkeyColumns: ["url"]). Leave the data-source fields empty. - Choose the event Run succeeded and save.
After every successful scraper run, this Actor gets the run's details (payload.resource.defaultDatasetId) and exports that run's dataset. You don't need to copy any IDs. If you prefer to be explicit, set Dataset to {{resource.defaultDatasetId}} in the integration input.
Input
| Field | Description |
|---|---|
spreadsheetId | Spreadsheet URL or ID (required). If the URL ends in #gid=..., that tab is used when sheetName is empty. |
serviceAccountKey | Full JSON key of your service account (secret input). |
sheetName | Tab to use. Created if it doesn't exist. Default: the tab in the URL, otherwise the first tab. |
mode | append (default), replace, upsert or read. |
keyColumns | Columns that identify a row. Required for upsert. With dedupe in append mode, only rows with new keys are added. |
dedupe | Skip rows already in the sheet and rows repeated in this run. Without keys, a row counts as a duplicate when all its values match. |
datasetId / items / jsonUrl | The data source; pick one. Leave all three empty when the Actor runs as an integration. jsonUrl accepts a JSON array, {items/data/results: [...]} or JSON Lines. |
fields | Columns to export, in this order. Key columns are always included. |
flatten / arraySeparator | address.city columns and joined arrays (default on, , ). When off, nested values are stored as JSON text. |
valueInputOption | RAW (default, safe) or USER_ENTERED (Google parses dates, numbers and formulas). |
maxRows | Process at most this many rows. |
maxRowsPerTab | Rollover: start <Tab> (2) when a tab has this many data rows. |
batchSize | Rows per write request (default 1000). |
dryRun | Report what would change and write nothing. Without a key, it only checks the data and the columns. |
{"spreadsheetId": "https://docs.google.com/spreadsheets/d/1AbC.../edit#gid=0","serviceAccountKey": "{ \"type\": \"service_account\", ... }","sheetName": "Products","mode": "upsert","keyColumns": ["url"],"datasetId": "aBcDeF123456"}
Output
Each run stores a summary in the key-value store under OUTPUT and also pushes it to the default dataset as one record. In read mode the dataset holds the sheet rows instead.
{"mode": "upsert", "dryRun": false, "sheetName": "Products","rowsInput": 1250, "rowsAppended": 140, "rowsUpdated": 85, "rowsSkipped": 1025,"skipped": {"duplicate": 3, "unchanged": 1022, "missingKey": 0, "empty": 0},"rowsNotWritten": 0, "columnsAdded": 1, "newColumns": ["discountPrice"],"tabsUsed": ["Products"], "tabsCreated": [], "spreadsheetFull": false, "chargeLimitReached": false,"spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1AbC.../edit","cellsUsed": 48210, "cellLimit": 10000000, "warnings": [], "error": null}
If the run fails, for example because the sheet isn't shared, the summary still lists how many rows were written before the error, and error holds the plain-English reason.
Pricing
Pay per event:
- USD 0.0001 per row written, i.e. USD 0.10 per 1,000 rows appended or updated.
- A start fee of USD 0.005 per run.
- Skipped, unchanged and duplicate rows are free, and so are dry runs (start fee only).
You can set a maximum cost per run in Apify Console. When the Actor reaches it, it stops writing cleanly, and the summary reports chargeLimitReached.
Run it from code or an AI agent
Everything the Console does is one API call away. Get your token under Settings > API & Integrations.
Python (pip install apify-client)
from apify_client import ApifyClientclient = ApifyClient("<APIFY_TOKEN>")run = client.actor("panthalus/google-sheets-sync").call(run_input={"spreadsheetId": "https://docs.google.com/spreadsheets/d/<ID>/edit","serviceAccountKey": open("service-account.json").read(),"mode": "upsert", "keyColumns": ["url"],"datasetId": "<DATASET_ID>",})print(client.key_value_store(run["defaultKeyValueStoreId"]).get_record("OUTPUT")["value"])
JavaScript (npm i apify-client)
import { ApifyClient } from 'apify-client';import { readFileSync } from 'node:fs';const client = new ApifyClient({ token: '<APIFY_TOKEN>' });const run = await client.actor('panthalus/google-sheets-sync').call({spreadsheetId: 'https://docs.google.com/spreadsheets/d/<ID>/edit',serviceAccountKey: readFileSync('service-account.json', 'utf8'),mode: 'append', dedupe: true,items: [{ name: 'Alpha', price: 9.5 }, { name: 'Beta', price: 12 }],});const { value } = await client.keyValueStore(run.defaultKeyValueStoreId).getRecord('OUTPUT');console.log(value);
cURL (runs the Actor and returns the summary in one request)
curl -X POST "https://api.apify.com/v2/acts/panthalus~google-sheets-sync/run-sync-get-dataset-items?token=<APIFY_TOKEN>" \-H "Content-Type: application/json" \-d '{"spreadsheetId": "<ID>", "serviceAccountKey": "<KEY JSON AS STRING>", "mode": "append", "jsonUrl": "https://example.com/data.json"}'
AI agents (MCP). Add this Actor as a tool in Claude, Cursor, VS Code or any MCP client:
https://mcp.apify.com?tools=panthalus/google-sheets-sync
Then you can just ask, for example: "Put these 40 leads into the 'Leads' tab of my sheet, and update any that are already there by email." The Actor uses pay-per-event pricing with limited permissions, so it is eligible for Apify's agentic payments.
Schedules. Run a scraper on an Apify Schedule and add this Actor as its integration. Your sheet then updates by itself.
FAQ
Is my data private? Do you store my key? No. Your data goes straight from your Apify dataset (or your JSON) to your Google Sheet, inside your own Apify run. We never store or see your data or your key. The key is an encrypted secret input: it's used only to get a short-lived Google access token, and it never appears in logs, outputs or error messages. The only thing the run saves is the summary, in your own run storage.
Why a service account and not "Sign in with Google"? A service account can only open the spreadsheets you explicitly share with it. It can't see the rest of your Drive, it doesn't expire like a login session, and you can revoke it any time by un-sharing the sheet or deleting the key.
"Your organization doesn't allow key creation". Some Google Workspace organizations block service-account keys through the policy iam.disableServiceAccountKeyCreation. Ask your admin to allow it for one project, or create the project under a personal Google account and share the sheet with that service account.
How fast is it? Google allows about 60 write requests per minute per service account, and each request carries up to 1,000 rows. Large exports move at tens of thousands of rows per minute. Upsert and dedupe first read the existing tab, which adds a few seconds per 10,000 rows.
What counts toward the 10M-cell limit? Every cell of every tab, including empty grid cells (a new tab already has 26,000 of them). The run summary shows cellsUsed. To free space, delete unused tabs or empty rows and columns, or use replace, which shrinks the tab to fit the data.
A run failed halfway. Will re-running create duplicates? Rows written before the error are listed in the summary. Re-run with upsert (with key columns) or dedupe on, and only the missing rows will be added.
My tab has blank rows in the middle. In plain append mode Google adds new rows after the first block of data, inserting them so that nothing is overwritten. If you want them strictly after the very last row, turn on dedupe or use upsert: the Actor then reads the tab and writes to exact row numbers.
Does replace delete anything else? It clears the chosen tab and deletes its rollover tabs (<Tab> (2), <Tab> (3)...). Other tabs are never touched.
Can it read a sheet? Yes: mode: "read" turns a tab into dataset items, with the header row as field names. Blank headers become column_C and repeated names become name_2.
Can I use an Excel file? Only after converting it: open it in Google Drive and choose File > Save as Google Sheets, then use the new spreadsheet's URL.
Developer: Panthalus.