# Google Sheets Export & Sync: append, upsert, dedupe (`arpitgoriya/google-sheets-export`) Actor

Send any Apify dataset to a Google Sheet with your own service account (your own quota). Append, replace, upsert by key or add only new rows, with dedupe, column selection and renaming, nested JSON flattening, batching and automatic retries. Works as an integration after any Actor run.

- **URL**: https://apify.com/arpitgoriya/google-sheets-export.md
- **Developed by:** [Arpit Goriya](https://apify.com/arpitgoriya) (community)
- **Categories:** Integrations, Developer tools, Automation
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.05 / 1,000 row writtens

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Google Sheets Export & Sync: append, upsert, dedupe

**Send any Apify dataset to a Google Sheet, with your own Google credentials, for $0.05 per 1,000 rows.**

Run it after any scraper and your results land in a Google Sheet, laid out the way you want:

- **4 write modes:** append, replace, **upsert by key** (update rows that already exist, add the others) and **append new only** (add only rows whose key isn't in the sheet yet).
- **Your own service account, your own quota.** Your exports don't share a Google quota with thousands of other users, so you don't get random "quota exceeded" failures.
- **Built for big and scheduled exports:** rows are written in large batches; Google rate limits (HTTP 429) and server errors are retried automatically with exponential backoff.
- **Clean columns:** nested JSON is flattened (`price.amount`), lists become `a, b, c`. Pick, order, rename and exclude columns. New fields are added as new columns on the right.
- **Remove duplicates** from the data before writing.
- **Works as an integration:** add it to any Actor or task and every finished run is exported automatically.
- **Clear errors** that tell you what to fix, e.g. *"Open the sheet → Share → add exporter@my-project.iam.gserviceaccount.com as Editor"*.
- **Free dry run:** without a key, or with **Dry run** on, it shows exactly what would be written and charges nothing.

It uses only the official Google Sheets API, with credentials you control. Your data goes straight from your Apify dataset to your sheet.

***

### Use cases

- **Scraper → spreadsheet pipelines.** Schedule a scraper daily and keep one Google Sheet up to date for your team or client, without duplicates.
- **Price and stock monitoring.** Upsert by product URL: prices update in place, new products are added, your own notes in other columns stay.
- **Lead lists.** Append only new leads (by email, domain or profile URL) to a sheet your sales team already works in.
- **Job, real-estate, review and news feeds.** "Append new only" turns any scraper into a growing, deduplicated feed.
- **Reporting.** Replace a tab with the latest numbers every morning and point your charts or Looker Studio at it.
- **No-code automations.** Many Zapier/Make/n8n flows start from a Google Sheet. Fill it from Apify with one integration.

### Setup: create a service account and share your sheet (5 minutes, once)

You need a Google Cloud **service account**: a robot Google account that writes to the sheets you share with it. It's free and doesn't need a credit card.

1. **Create a project.** Open [console.cloud.google.com/projectcreate](https://console.cloud.google.com/projectcreate), enter a name (e.g. `apify-sheets`) and click **Create**. Make sure the new project is selected at the top of the page.
2. **Enable the Google Sheets API.** Open [the Sheets API page](https://console.cloud.google.com/apis/library/sheets.googleapis.com) and click **Enable**.
3. **Create the service account.** Go to **IAM & Admin → Service accounts** ([direct link](https://console.cloud.google.com/iam-admin/serviceaccounts)) → **Create service account**. Give it a name such as `apify-export` and click **Done**. It needs no roles.
4. **Create a key.** Click the new service account → **Keys** tab → **Add key → Create new key → JSON → Create**. A `.json` file is downloaded. Keep it private: it is the password of this robot account.
   - If your organization blocks key creation (policy `iam.disableServiceAccountKeyCreation`), ask your Google Workspace admin, or use a personal Google account for this project.
5. **Share your sheet.** Copy the service account's email (it looks like `apify-export@apify-sheets.iam.gserviceaccount.com`). Open your Google Sheet → **Share** → paste the email → role **Editor** → untick *Notify people* → **Share**.
6. **Paste the key into the Actor.** Open the downloaded JSON file in a text editor, copy **everything** and paste it into **Service account key (JSON)**. Apify stores this field encrypted, and it is never written to logs or outputs.

Tip: save your settings as an Apify **task** (Actor page → *Save as a new task*), so you paste the key only once.

The service account can only open sheets you share with it. To stop access, remove it from the sheet's sharing or delete the key in Google Cloud.

### How to use it

#### Export one dataset

1. Click **Try for free**.
2. **Google Sheet URL or ID:** paste the sheet's URL from your browser. The tab in the URL (`#gid=…`) is used, or set **Sheet (tab) name** (it's created if it doesn't exist).
3. **Service account key (JSON):** paste the key (see the setup guide above).
4. **Dataset:** pick the dataset, or enter a **Run ID** to export that run's results.
5. Choose a **Mode** and click **Start**.

#### Export every run of another Actor automatically (integration)

1. Open the Actor or task whose results you want in the sheet (for example your scraper) → **Integrations** tab.
2. Choose **Connect Actor or task** → search for **Google Sheets Export & Sync**.
3. Set the sheet URL, key, mode and columns, and leave **Dataset** empty. Each time that Actor's run succeeds, its dataset is exported. The triggering run's dataset ID is passed automatically.

Easiest: first save this Actor's settings as a task, then connect that task.

#### From the API, Make, Zapier or n8n

Call this Actor with `datasetId` (or `runId`) in the input, for example in a "run Actor" step right after your scraper step.

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/1AbC…/edit#gid=0",
  "serviceAccountKey": "{ \"type\": \"service_account\", … }",
  "datasetId": "WkzbQMuFYuamGv3YF",
  "sheetName": "Products",
  "mode": "upsert",
  "keyColumns": ["url"],
  "columns": ["url", "title", "price.amount", "price.currency", "inStock"],
  "columnNames": { "price.amount": "Price", "price.currency": "Currency" }
}
```

### Write modes

| Mode | What it does | Typical use |
|---|---|---|
| **Append** (default) | Adds all rows below the existing ones. | Logs, history, one-off exports |
| **Replace** | Overwrites the tab with this data (header + rows); old rows and columns beyond the new data are cleared. | "Latest snapshot" tabs, dashboards |
| **Upsert** | Finds rows with the same **key columns** and updates them; adds rows whose key is new. Columns the data doesn't have (e.g. your own notes) are kept. Unchanged rows aren't rewritten and are free. | Price/stock tracking, CRM-like lists |
| **Append new only** | Adds only rows whose key isn't in the sheet yet; existing rows are never touched. | Lead lists, job/news feeds, monitoring |

**Header row:** row 1 holds the column names. In an empty tab it's created for you. In a tab that already has a header, data is matched to columns **by name** (order doesn't matter), and new fields are added as new columns on the right (turn off **Add new columns** to skip them instead).

**Keys** can be one column (`url`) or several (`["sku", "store"]`). You can use the field name or the renamed header. Key matching ignores leading and trailing spaces.

### Input options

| Option | Default | What it does |
|---|---|---|
| `spreadsheet` | — | Sheet URL or ID. |
| `serviceAccountKey` | — | Service account JSON key (secret). Empty = dry run. |
| `sheetName` | tab from URL, else first tab | Tab to write to; created if missing. |
| `datasetId` | — | Dataset to export. Empty when used as an integration. |
| `runId` | — | Export this run's default dataset instead. |
| `offset`, `maxItems` | `0`, `0` (all) | Read only part of the dataset. |
| `mode` | `append` | `append`, `replace`, `upsert`, `appendNew`. |
| `keyColumns` | `[]` | Key columns for upsert / append new only / dedupe. |
| `dedupe` | `false` | Remove repeated rows from the data (by key columns, or identical rows). |
| `columns` | all | Fields to export, in this order. `price` includes `price.amount` and `price.currency`. |
| `excludeColumns` | `[]` | Fields to leave out. |
| `columnNames` | `{}` | Rename columns: `{"price.amount": "Price"}`. |
| `addNewColumns` | `true` | Add new fields as columns on the right. |
| `arrayMode` | `join` | Lists: `join` (`a, b, c`), `json` (`["a","b","c"]`) or `expand` (`tags.0`, `tags.1`…). |
| `valueInputOption` | `RAW` | `RAW` writes values exactly. `USER_ENTERED` lets Sheets parse dates and formulas, as if typed. |
| `dryRun` | `false` | Check everything and report, without writing or charging. |

Values keep their type: numbers stay numbers, `true`/`false` stay booleans, everything else is text. With the default **Raw** setting, scraped text that starts with `=` is stored as text and can never run as a formula.

### Output

The sheet is the main output. The run also saves a short summary (dataset + `RUN_SUMMARY` record):

```json
{
  "dryRun": false,
  "mode": "upsert",
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1AbC…/edit",
  "spreadsheetTitle": "Competitor prices",
  "sheetName": "Products",
  "datasetId": "WkzbQMuFYuamGv3YF",
  "itemsRead": 1250,
  "columns": 6,
  "header": ["url", "title", "Price", "Currency", "inStock", "my notes"],
  "rowsAppended": 40,
  "rowsUpdated": 212,
  "rowsUnchanged": 998,
  "rowsSkippedExisting": 0,
  "duplicatesRemoved": 0,
  "rowsWritten": 252,
  "apiRequests": 6,
  "retries": 0,
  "durationSecs": 4.1
}
```

A dry run also saves a `PREVIEW` record with the header and the first 20 rows exactly as they would be written.

### How much does it cost?

You pay only when rows are actually written. No subscription, no start fee for runs that write nothing.

| Event | Price | |
|---|---|---|
| Row written (appended, replaced or updated) | **$0.00005** | **$0.05 per 1,000 rows** |
| Sheet sync (once per run that writes at least one row) | **$0.005** | |
| Dry runs, unchanged rows, duplicates, rows already in the sheet, failed runs | free | |

Examples:

| Job | Cost |
|---|---|
| Export a 1,000-row scrape once | $0.055 |
| Daily upsert of 2,000 products where ~150 change | ~$0.0125 a day, ~$0.38 a month |
| Hourly "append new only" lead feed, ~20 new leads per run | ~$0.006 per run |
| Replace a 50,000-row tab | $2.505 |

Platform usage is included. Google doesn't charge for the Sheets API. Set a **maximum cost per run**: if a run would cost more, it stops **before writing anything** and tells you, so you never get a half-written sheet because of the limit.

#### How it compares

| | **This Actor** | Typical Sheets export Actor | Apify's built-in Google Drive integration |
|---|---|---|---|
| Google quota | **Your own** (service account) | Often shared by all users → "quota exceeded" | Your account |
| Upsert by key / append only new | ✅ | Partly | ❌ (uploads a file) |
| Dedupe, column pick / rename / order | ✅ | Partly | ❌ |
| Backoff on 429 / 5xx | ✅ automatic | Varies | — |
| Writes into an existing tab, keeps your other columns | ✅ | Varies | ❌ |
| Free dry run with preview | ✅ | ❌ | — |

### Limits and tips

- **Google Sheets limits:** 10 million cells per spreadsheet and 50,000 characters per cell. The Actor checks the cell limit **before writing** and stops with a clear message; longer cells are shortened (the summary counts them). For big data, export only the columns you need, or use a new tab or spreadsheet per month.
- **Speed:** up to 10,000 rows (about 2 MB) per API request, so a 50,000-row export needs only about 5–10 write requests. Upsert and append-new-only read the whole tab first, so very large tabs (over 1 million cells) take longer: give the run more memory (1–2 GB).
- **Google quota:** your project allows 60 write requests per minute per service account by default. Each run uses only a few requests, so you'd only hit it with many parallel runs. Then the Actor waits and retries.
- **Memory:** the default 512 MB is enough for about a million cells.
- **Don't edit the tab while a big replace or upsert runs.** Rows you insert or sort during the run can shift the positions being written.
- **Free dry runs** read at most the first 1,000 items.

### Use it from AI agents (MCP)

This Actor is available as a tool through the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp), so Claude, ChatGPT, Cursor, VS Code, n8n and any other MCP client can call it directly. The input schema becomes the tool's parameters automatically.

Load **only this Actor** as a tool (remote server, sign in with Apify on first connect):

```json
{
  "mcpServers": {
    "google-sheets-export": {
      "url": "https://mcp.apify.com?tools=arpitgoriya/google-sheets-export"
    }
  }
}
```

Or run the MCP server locally (stdio):

```bash
npx -y @apify/actors-mcp-server --tools arpitgoriya/google-sheets-export
```

Then an agent can finish a scraping job by writing the results to your sheet, for example: *"Scrape these 20 job boards, then upsert the results into my 'Jobs' sheet by URL."* Save your key in an Apify task so the agent doesn't need to see it.

### FAQ

**Why a service account instead of "Sign in with Google"?** A service account is a key that you create and control, and it works for scheduled runs without anyone being logged in. You decide exactly which sheets it can open by sharing them with it. It also means your own Google quota instead of one shared by every user of the Actor.

**Is my key safe?** The key field is a secret input: Apify encrypts it, and it's hidden in the Console, logs and the run's input. The Actor only uses it to get a short-lived Google token with the Sheets scope. The service account can't see anything you haven't shared with it.

**The run failed with "can't open the spreadsheet".** Share the sheet with the service account's email (shown in the error) as **Editor**. Also check the URL: it must be a Google Sheets file, not an uploaded `.xlsx` file. Open it and use *File → Save as Google Sheets* first.

**"The Google Sheets API is not enabled in your Google Cloud project".** Open the link in the error, click **Enable**, wait a minute and run again.

**Can I use "Anyone with the link → Editor" instead of adding the email?** It works (tested), but then anyone who has the link can edit your sheet. Adding the service account's email as Editor is safer and is what we recommend.

**Can I write to a sheet in a shared drive?** Yes. Share the sheet (or the shared drive) with the service account as Editor.

**My dates show up as text.** With the default **Raw** setting, values are stored exactly as they appear in the data. Choose **Cell values: As if typed** to let Google parse dates and numbers.

**Can I export to CSV or Excel instead?** Apify's dataset already exports CSV, Excel, JSON and XML for free: open the dataset and click **Export**. This Actor is for when you want the data inside Google Sheets.

**Does it read my other sheets or files?** No. It reads only the tab it writes to (header, plus the rows for upsert / append new only).

### Other tools from us

- [Website Screenshot & PDF Generator](https://apify.com/arpitgoriya/website-screenshot-pdf): full-page screenshots and PDFs of any web page.
- [Website Tech Stack Lookup & Domain Intel](https://apify.com/arpitgoriya/website-tech-stack-lookup): technologies, DNS, email provider and hosting for any domain.
- [Document to Markdown & JSON for AI/RAG](https://apify.com/arpitgoriya/document-to-markdown): PDF, DOCX, PPTX, XLSX and HTML to clean Markdown with RAG-ready chunks.
- [Company Jobs Feed](https://apify.com/arpitgoriya/company-jobs-feed): live jobs from Greenhouse, Lever, Ashby, Workable and more, with new-jobs-only monitoring.

### Feedback and support

Something didn't export the way you expected, or need a feature (CSV/XLSX file output, Excel Online, formatting)? Open an issue on the **Issues** tab. We read every issue and reply as quickly as we can.

Google Sheets is a trademark of Google LLC. This Actor is not affiliated with or endorsed by Google.

# Changelog

This Actor's version history is a separate document: https://apify.com/arpitgoriya/google-sheets-export/changelog.md

# Actor input Schema

## `spreadsheet` (type: `string`):

Copy the URL from your browser, e.g. https://docs.google.com/spreadsheets/d/1AbC…/edit#gid=0. The sheet must be shared with your service account's email as Editor (see the setup guide in the README).

## `serviceAccountKey` (type: `string`):

Paste the whole content of the JSON key file of your Google Cloud service account (it contains "client_email" and "private_key"). Stored encrypted. Using your own key means your own Google quota: no shared-quota errors. Leave empty for a free dry run.

## `sheetName` (type: `string`):

Tab to write to. Created if it doesn't exist. Empty = the tab in the URL (#gid=…), otherwise the first tab.

## `datasetId` (type: `string`):

The dataset to export. Leave empty when this Actor runs as an integration after another Actor (the run's dataset is passed automatically) or when you give a Run ID.

## `runId` (type: `string`):

Alternative to Dataset: export the default dataset of this Actor run.

## `offset` (type: `integer`):

Start reading the dataset at this position.

## `maxItems` (type: `integer`):

Read at most this many dataset items (0 = all).

## `mode` (type: `string`):

How the data is written. Upsert and Append new only need Key columns.

## `keyColumns` (type: `array`):

Column(s) that identify a row, e.g. "url" or "id" (field name or the renamed header). Needed for Upsert and Append new only; also used by Remove duplicates.

## `dedupe` (type: `boolean`):

Drop repeated rows from the dataset before writing (same key columns, or identical rows when no key is set). Upsert and Append new only always do this by key.

## `columns` (type: `array`):

Only export these fields, in this order. Use dots for nested fields ("price.amount"); a parent ("price") includes all its sub-fields. Empty = all fields.

## `excludeColumns` (type: `array`):

Fields to leave out (e.g. "descriptionHtml", "debug").

## `columnNames` (type: `object`):

Header names to use instead of field names, e.g. {"price.amount": "Price", "url": "Link"}.

## `addNewColumns` (type: `boolean`):

When the data has fields the sheet's header doesn't have yet, add them as new columns on the right. Off = keep the sheet's columns and skip the rest.

## `arrayMode` (type: `string`):

How lists inside items are written. Nested objects are always flattened into dotted columns.

## `valueInputOption` (type: `string`):

Raw stores text exactly, so scraped text starting with "=" can never run as a formula. Use "As if typed" if you want Sheets to parse dates and formulas.

## `dryRun` (type: `boolean`):

Read the data (and the sheet, if a key is given) and report what would be written, without writing or charging anything.

## Actor input object example

```json
{
  "offset": 0,
  "maxItems": 0,
  "mode": "append",
  "dedupe": false,
  "columnNames": {},
  "addNewColumns": true,
  "arrayMode": "join",
  "valueInputOption": "RAW",
  "dryRun": false
}
```

# Actor output Schema

## `summary` (type: `string`):

No description

## `preview` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "columnNames": {}
};

// Run the Actor and wait for it to finish
const run = await client.actor("arpitgoriya/google-sheets-export").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "columnNames": {} }

# Run the Actor and wait for it to finish
run = client.actor("arpitgoriya/google-sheets-export").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "columnNames": {}
}' |
apify call arpitgoriya/google-sheets-export --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,arpitgoriya/google-sheets-export"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/r3LMrG12A0hjJhZ9H/builds/tkR1gkhBFcLnpfXAg/openapi.json
