# Google Sheets Sync: append, replace or update rows (`geyserworks/sheets-sync`) Actor

Send any Apify dataset to a Google Sheet. No Google sign-in: just share your sheet with the add-on's email. Append, replace, update rows by key, or add only new rows.

- **URL**: https://apify.com/geyserworks/sheets-sync.md
- **Developed by:** [Craig](https://apify.com/geyserworks) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.10 / 1,000 row written to your sheets

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/running/actors-in-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 Sync: append, replace or update rows

Send any Apify dataset to a Google Sheet. Add it to a scraper once, and every run lands in your sheet automatically.

- **No Google sign-in pop-up.** Share your sheet with our robot email, and that's it.
- **Any sheet link works.** Paste the link straight from your browser's address bar, including links from a second Google account (`/u/1/`) or a specific tab (`#gid=`).
- **Four modes:** Append, Replace, Update rows by key, or Add only new rows. Update and Add new never create duplicate rows.
- **Your own columns are safe.** Updating a row only touches the columns that come from your data, so a "Notes" or "Status" column you added by hand stays as it is.
- **Errors in plain English**, telling you exactly what to fix.

### Quick start

1. **Share your sheet.** In Google Sheets, click **Share** and add **sheets-sync@my-project-1704420827892.iam.gserviceaccount.com** as an **Editor**.
2. **Add the integration.** Open your scraper, go to its **Integrations** tab, click **Add integration**, and choose **Google Sheets Sync**. The scraper's results are passed in automatically.
3. **Paste your sheet link**, choose a mode, and save. Every finished run now writes to your sheet.

You can also run it on its own: pick a dataset in **Dataset**, or paste JSON rows in **Or paste rows** for a quick test.

**Try it without a sheet:** press Start with the example rows and no sheet link. You get a preview of the rows and columns it would write. Nothing is written and no rows are charged.

### Modes

| Mode | What happens to rows already in the tab |
|---|---|
| **Append** (default) | Kept. Every item is added as a new row at the end. |
| **Replace** | The tab is cleared, then the new rows are written. Nothing is cleared if the run has no data. |
| **Update** | Rows with the same key (for example `url` or `id`) are updated in place. Other items are added as new rows. |
| **Add new only** | Rows whose key is already in the tab are left alone. Only new keys are added. |

Update and Add new need **Key column(s)**: one or more fields that identify a row. Several key columns work together (for example `shop/id` + `sku`).

### How your data is written

- **Row 1 is the header.** Each field gets a column, and new fields are added on the right. If the tab already has a header, data goes into the matching columns, whatever their order.
- **Nested fields are flattened with a slash**, like Apify's CSV export: `address/city`, `price/value`.
- **Lists** stay in one cell as JSON text by default. Set **Lists** to "Spread lists over columns" to get `images/0`, `images/1`, and so on.
- **Text stays text.** Values are written exactly as they are, so a value starting with `=` is never run as a formula, and `00123` keeps its zeros.
- Very large integers (above 9,007,199,254,740,992) are written as text so no digits are lost.
- Google allows 50,000 characters per cell. Longer values are cut, and the run's summary says how many.
- **Only these columns** writes just the fields you list, in that order.
- **Tab name** picks the tab. It is created if it doesn't exist. Leave it empty to use the tab in your link, or the first tab.

### Pricing

Pay per event: a small charge per run, plus a charge per row actually written to your sheet (added or updated). Rows that are skipped, or that fail to write, are not charged. The run respects your **max cost per run** limit: it stops cleanly when the limit is reached and tells you. See the **Pricing** tab for current prices.

### Privacy and security

- The robot can only open sheets you share with it, and it only asks Google for access to spreadsheets, not to the rest of your Drive.
- Your data passes straight from Apify to Google. The add-on keeps no copy.
- You can stop access at any time: remove the robot email from the sheet's Share settings.
- Prefer your own robot? Paste your own Google service-account JSON key in **Your own Google key** (stored encrypted), then share the sheet with that key's email instead.
- It runs with Apify's **limited permissions**: it can read only the dataset it is given, nothing else in your account.

### Output

Each run's **Output** tab shows a one-line summary with a link to your sheet. The full details are saved under the `OUTPUT` key in the run's key-value store, for example:

```json
{
  "spreadsheet_title": "Leads",
  "sheet_name": "Sheet1",
  "spreadsheet_url": "https://docs.google.com/spreadsheets/d/.../edit#gid=0",
  "appended": 120,
  "updated": 30,
  "skipped_existing": 0,
  "rows_written": 150,
  "stopped_at_charge_limit": false
}
```

### Troubleshooting

| Message | Fix |
|---|---|
| "The add-on can't open this spreadsheet yet" | Share the sheet with sheets-sync@my-project-1704420827892.iam.gserviceaccount.com as an **Editor** (not Viewer). |
| "No Google Sheet was found" | Copy the link again while the sheet is open. Uploaded Excel files must be saved as Google Sheets first (File > Save as Google Sheets). |
| "This spreadsheet is full" | Google allows 10 million cells per spreadsheet. Use a new spreadsheet, delete old tabs, or use Replace mode. |
| "Couldn't read the dataset" | When running on its own, choose the dataset in the **Dataset** field so Apify gives the add-on access. |
| Google is limiting how fast we can write | The add-on already waits and retries. If it still fails, run again in a few minutes. |

### Limits

- Google Sheets limits: 10 million cells per spreadsheet, 18,278 columns, 50,000 characters per cell.
- Update and Add new read the key column(s) from the tab at the start of each run, so very large tabs take a little longer.

### Support

Found a bug or missing a feature? Open an issue on the **Issues** tab. Issues are answered within a week.

# Actor input Schema

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

Paste the link to your Google Sheet (any link or ID works). Before the first run, click Share in the sheet and add sheets-sync@my-project-1704420827892.iam.gserviceaccount.com as an Editor.

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

The tab to write to. It is created if it doesn't exist. Leave empty to use the tab in your link, or the first tab.

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

What to do with the rows already in the tab. Row 1 is always the header.

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

For Update and Add new only: the field(s) that identify a row, such as url or id. Nested fields use a slash, like product/id.

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

Filled in for you when you add this add-on on a scraper's Integrations tab. To run it on its own, pick a dataset here.

## `items` (type: `array`):

Instead of a dataset, paste a JSON array of objects, like \[{"name": "A", "price": 10}]. Handy for a quick test. Run with rows here and no sheet link to get a free preview of the columns; nothing is written.

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

Write only these fields, in this order. Leave empty to write every field. Nested fields use a slash, like address/city.

## `arrays` (type: `string`):

How to write fields that hold a list of values.

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

Optional. Paste a Google service-account JSON key to write as your own robot instead of ours. Then share the sheet with that key's client_email. Stored encrypted.

## Actor input object example

```json
{
  "mode": "append",
  "items": [
    {
      "name": "Blue mug",
      "price": 12.5,
      "url": "https://example.com/blue-mug"
    },
    {
      "name": "Red mug",
      "price": 11,
      "url": "https://example.com/red-mug"
    }
  ],
  "arrays": "json"
}
```

# Actor output Schema

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

No description

## `details` (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 = {
    "items": [
        {
            "name": "Blue mug",
            "price": 12.5,
            "url": "https://example.com/blue-mug"
        },
        {
            "name": "Red mug",
            "price": 11,
            "url": "https://example.com/red-mug"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("geyserworks/sheets-sync").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 = { "items": [
        {
            "name": "Blue mug",
            "price": 12.5,
            "url": "https://example.com/blue-mug",
        },
        {
            "name": "Red mug",
            "price": 11,
            "url": "https://example.com/red-mug",
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("geyserworks/sheets-sync").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 '{
  "items": [
    {
      "name": "Blue mug",
      "price": 12.5,
      "url": "https://example.com/blue-mug"
    },
    {
      "name": "Red mug",
      "price": 11,
      "url": "https://example.com/red-mug"
    }
  ]
}' |
apify call geyserworks/sheets-sync --silent --output-dataset

```

## MCP server setup

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

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/lm9D4Flm74Jda4g1r/builds/0j01ujAMeJAfZzjOp/openapi.json
