# Google Sheets Import & Export – Datasets to Sheets and Back (`extractlyspace/google-sheets-sync`) Actor

Writes Apify dataset rows to a Google Sheet (append, replace or upsert by key) and reads sheet tabs back as dataset rows. Share the sheet with our service account and add a tab naming your Apify account; no Google login.

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

## Pricing

from $0.01 / 1,000 rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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 Import & Export – Datasets to Sheets and Back

This Actor writes the rows of an Apify dataset (or rows you send) to a tab of a Google Sheet, and reads a tab back as dataset rows. Export appends, replaces or upserts by a key column; import returns one row per sheet row. To use a sheet, share it with `sheets-sync@monday-brief-507421.iam.gserviceaccount.com` (Editor to export, Viewer to import) and add a tab named `apify-<your Apify user id>`. No Google login and no Google credentials from you.

### Set up a sheet (once per sheet)

1. **Share the sheet** with `sheets-sync@monday-brief-507421.iam.gserviceaccount.com`: **Editor** to export, **Viewer** to import.
2. **Add a tab** named `apify-<your Apify user id>`, for example `apify-AbC123xYz45678901` (a user id is 17 letters and digits). It can be empty and hidden. Your user id is in Apify Console under Settings. If you skip this step, the first run answers `not_shared` and names the exact tab to add.

A teammate on another Apify account adds a tab with their own id. A sheet that is public ("Anyone with the link" can view) needs neither step to import: pass the URL of the tab (with `#gid=`) and leave `sheetName` empty.

### Use this to

- **Send scraper results to a sheet**: "After every run of my scraper, append the new rows to the tab `Leads`."
- **Keep a sheet in sync**: "Update rows by `id`, add the new ones" (`writeMode: upsert`, `keyColumn: id`).
- **Read a sheet in a workflow or from an AI agent**: "Read the tab `Targets` and use the rows as input for the next Actor."

### Export from another Actor in three clicks

1. Open the Actor whose results you want in the sheet, go to Integrations and choose **Google Sheets Import & Export** (an Actor-to-Actor integration), trigger "run succeeded".
2. Paste this as the integration's input, with your sheet's URL:

```json
{"mode": "export", "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1XIrxiVSWCaeSZOSyORrM8cbRkDEIjZmxvUjGlfz3VQA/edit", "datasetId": "{{resource.defaultDatasetId}}"}
```

3. Save. Every finished run now sends its dataset to the sheet.

Console integrations fill in `{{resource.defaultDatasetId}}` for you. If you create the integration through the webhooks API, set `shouldInterpolateStrings: true`.

### Pricing

You pay per event:

- `row`: $0.00002 for each row written, updated or read. That is $0.20 per 10,000 rows. Store discounts apply to the price: Bronze −10%, Silver −20%, Gold, Platinum and Diamond −30%.

Examples: exporting 500 rows costs $0.01. Importing 10,000 rows costs $0.20. A nightly upsert of 2,000 rows costs $0.04 a run.

Rows skipped because their key is already in the sheet, summary rows and status rows are never charged. The run stops when it reaches your spending limit.

### Input

- **mode** (required): `export` writes rows to the sheet; `import` reads a tab and returns its rows.
- **spreadsheetUrl** (required): the sheet's URL or id.
- **sheetName**: the tab to write or read. Empty: the tab of the URL's `#gid=`, else the first tab. Export creates a missing tab. A name of the form `apify-<Apify user id>` is refused; other names that start with `apify-` are fine.
- **datasetId** (export): the dataset to export. Use it or `rows`, not both.
- **rows** (export): up to 1,000 flat objects to export directly, instead of a dataset. Meant for AI agents and MCP calls.
- **writeMode** (export): `append` (default) adds rows below the last row and, with `keyColumn`, skips keys already in the sheet; `replace` clears the tab first and writes everything; `upsert` updates the rows whose key matches and appends the rest.
- **keyColumn** (export): the column that identifies a row, for example `id`. Required for `upsert`.
- **columns** (export): the columns to write, in order. Empty: all keys, in first-seen order.
- **maxRows**: the most rows to write or read in this run, 1 to 100,000 (default 10,000). Each row is charged.

### Output

Export pushes one free `summary` row: `recordType`, `spreadsheetId`, `sheetName`, `sheetUrl` (a link to the tab), `rowsWritten`, `rowsUpdated`, `rowsSkipped`, `columns` (the header after the run, joined with commas) and `mode`. A run that wrote nothing returns a `status` row instead.

Import pushes one row per sheet row, with `recordType: "row"`, `_rowNumber` (the sheet row; row 1 is the header), `_sheetName`, and one key per header cell. Values come back as the sheet shows them, as strings (`"1,200"` stays `"1,200"`); empty cells are empty strings. Completely empty rows are skipped. An empty or repeated header gets the name `column_3` or `name_2`.

### How rows are written

- **Flattening**: nested values become columns the way Apify's CSV export does: `address.city` for an object, `tags/0` for a list item.
- **Raw values**: cells are written as-is. A value starting with `=` stays text and is never run as a formula.
- **Header**: a new tab gets the header from the first rows. New columns are added to the right of existing ones. Existing columns are never reordered or removed.
- **Upsert** blanks the cells of columns an item lacks, for the matched row.
- **Replace** clears the tab first, then writes. It changes nothing unless the spending limit pays for every row: then it returns only `limit_reached`, and the tab stays as it was. If Google's quota stops the run right after the clearing, the tab is left empty, and the status row says so.
- **Append after a timeout**: Google may have accepted a write the Actor never heard back about. The Actor never repeats such an append itself (only a request Google refused with "too many requests" is sent again), but a run you repeat can write rows twice. Set `keyColumn` and the rows already in the sheet are skipped.

### Limits

- A spreadsheet holds at most 10 million cells. An export that would go over it writes nothing and returns `too_large`.
- Google allows 60 write requests and 60 read requests a minute for the service account, shared by all users of this Actor. The Actor backs off and retries: a request Google turns away as too many is sent again up to five times (after 0.5, 1, 2, 4 and 8 seconds). If Google still does not answer, it returns `partial` and what was written stays in the sheet. Run again a minute later.
- Rows are written in requests of at most 5,000 rows and about 4 MB, and read in windows of 1,000 rows.
- 1 to 100,000 rows per run (`maxRows`); `rows` accepts up to 1,000.

### What you get when something is wrong

An input the form itself rejects is refused before the run starts. Otherwise the run succeeds and returns a `status` row (`recordType: "status"`, with `status`, `message` and `subject`), never an empty dataset. The run fails only when Google or Apify could not be reached and nothing was delivered. The `status` is one of:

- `invalid_input`: the URL is not a Google Sheets URL or id; export without exactly one of `datasetId` and `rows`; more than 1,000 `rows`; `upsert` without `keyColumn` (`keyColumn is required when writeMode is "upsert". Example: {"writeMode": "upsert", "keyColumn": "id"}`); a `keyColumn` that is not in the written columns or the sheet's header; a `sheetName` of the form `apify-<Apify user id>`; a URL that points at such a tab; a request Google refuses before any row moved (status 400): `Google Sheets refused the request (status 400): the tab may not exist, a range may lie outside the sheet, or the request may be too large (…). No row was written.` (on import: `Nothing was read.`).
- `not_shared`: `To let this Apify account use the sheet, share it with <email> as Editor (export) or Viewer (import), add a tab named apify-<your id> (you can hide it), and run again.` Also, after a refused write: `Share the sheet with <email> as Editor, then run again.`
- `not_found`: the spreadsheet, the tab or the dataset does not exist (or this run may not read the dataset). The message lists the tabs of the sheet.
- `no_results`: the dataset has no items, the items have no fields, or the imported tab has no data rows below the header.
- `too_large`: `This export would grow the spreadsheet to N cells; Google allows 10,000,000 per spreadsheet. Write fewer rows or columns, …`
- `partial`: `Google Sheets did not answer (quota or time ran out); no row was written. Run again in a minute.` or `… after the tab was cleared; no row was written.` or `Google Sheets stopped answering … after N of M rows were written or updated; the rows already written stay in the sheet.` On import: `… after N rows were read; those are returned.` When Google refused a request (status 400) after some rows: `Google Sheets refused the request (status 400): … N of M rows were written or updated before it; those stay in the sheet.` (on import: `N rows were read before it; those are returned.`). A refusal is not an outage: the run succeeds, and running it again unchanged gives the same answer. Also `Dataset … could not be read right now (Apify did not answer) …` and, for a public link that did not answer, `Google did not answer on the sheet's public link (busy or timed out) …`.
- `limit_reached`: `Stopped: the spending limit for this run was reached. N of M rows were written or updated and K left out. Raise the limit and run again.` With `replace`: `The spending limit pays for N of M rows, so the tab was not changed. Raise the limit or use append.` On import: `Returned N of M rows.`

### What it never does

It never reads or writes anything outside the spreadsheet you share, never stores your sheet's content or your Apify token, and never asks for a Google login. It does not read other tabs than the one you name.

### FAQ

**Why share with an email and not sign in?** Signing in would hand this Actor your Google account. Sharing one sheet with a service account gives access to that sheet only, and you can remove it at any time in the sheet's sharing settings. The Actor holds no login of yours and stores nothing about you.

**Why the extra tab?** All users share one service account, so the sheet's id alone must not open a sheet for anyone who knows it. The tab named `apify-<your Apify user id>` shows that someone who can edit the sheet authorised your Apify account: only editors can add a tab. The Actor stores nothing for this; it looks for the tab on every run. The id is not a secret.

**Where do I find my Apify user id?** In Apify Console under Settings. The first run without the tab also tells you the exact tab name.

**Can I import a public sheet without sharing?** Yes. Pass the URL of the tab (with `#gid=`) and leave `sheetName` empty. The sheet must be viewable by anyone with the link.

**Do numbers and dates keep their format on import?** Values come back as the sheet shows them, as strings. Convert them in your next step.

**Can it write to the same tab as another run at the same time?** Avoid it. Two runs appending at once can interleave rows; use `keyColumn` to keep them unique.

This Actor reports usage statistics to its developer to keep it reliable: the Actor's name and build number, the time of the run, the run's outcome, row counts, events charged, an estimate of the revenue from those events, an estimate of what paid data sources cost for the run (always zero for this Actor), duration, a short error category when a run fails, partly fails or meets upstream data in an unexpected shape, how the run was started, whether the account is on a paid plan, and a one-way hash of the Apify user ID. It never reports your inputs, your sheet's content or the data returned.

# Actor input Schema

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

export writes rows to the sheet; import reads a tab and returns its rows. Example: export

## `spreadsheetUrl` (type: `string`):

Sheet URL or id. Share it with sheets-sync@monday-brief-507421.iam.gserviceaccount.com (Editor to export, Viewer to import) and add a tab apify-<your Apify user id>. Public tabs import by URL alone. Example: https://docs.google.com/spreadsheets/d/1XIrxiVSWCaeSZOSyORrM8cbRkDEIjZmxvUjGlfz3VQA/edit

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

Tab to write or read. Empty: the tab of the URL's gid, else the first tab. Export creates a missing tab. apify-<user id> tab names are not allowed. Example: Prefill demo

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

Apify dataset to export. In an integration use {{resource.defaultDatasetId}}. Use this or rows, not both. Example: wBxbrkYpUUDV3Hzkg

## `rows` (type: `array`):

Up to 1,000 flat objects to export directly, instead of a dataset. Example: \[{"id": 1, "name": "Ada"}]

## `writeMode` (type: `string`):

append adds rows (skips keys already present if keyColumn is set), replace clears the tab first, upsert updates matching keys. Example: append

## `keyColumn` (type: `string`):

Column that identifies a row. Required for upsert; with append it skips rows already in the sheet. Example: id

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

Pick and order the columns to write. Empty: all keys in first-seen order. Example: \["id", "name"]

## `maxRows` (type: `integer`):

Most rows to write or read in this run, from 1 to 100,000. Each row is charged. Example: 500

## Actor input object example

```json
{
  "mode": "import",
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1XIrxiVSWCaeSZOSyORrM8cbRkDEIjZmxvUjGlfz3VQA/edit#gid=2015088071",
  "writeMode": "append",
  "maxRows": 10000
}
```

# Actor output Schema

## `rows` (type: `string`):

Import: one row per sheet row (recordType "row"). Export: one summary row (recordType "summary") with the counts and a link to the tab. A run that could not do its job gives an explanatory row instead (recordType "status", with status, message and subject).

# 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 = {
    "mode": "import",
    "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1XIrxiVSWCaeSZOSyORrM8cbRkDEIjZmxvUjGlfz3VQA/edit#gid=2015088071"
};

// Run the Actor and wait for it to finish
const run = await client.actor("extractlyspace/google-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 = {
    "mode": "import",
    "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1XIrxiVSWCaeSZOSyORrM8cbRkDEIjZmxvUjGlfz3VQA/edit#gid=2015088071",
}

# Run the Actor and wait for it to finish
run = client.actor("extractlyspace/google-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 '{
  "mode": "import",
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1XIrxiVSWCaeSZOSyORrM8cbRkDEIjZmxvUjGlfz3VQA/edit#gid=2015088071"
}' |
apify call extractlyspace/google-sheets-sync --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,extractlyspace/google-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/4ghhCJID2Xdrf34rA/builds/gYUJ1CAjfGphsR80i/openapi.json
