# Google Sheets Import & Export: Sync Datasets, Update Rows (`s_actors/google-sheets-import-export`) Actor

Send any Apify dataset or JSON to Google Sheets: append, replace, or update rows by a unique key (price and stock monitoring). No OAuth: share the sheet once. Auto-retries on Google limits, one tab per day, dedupe, column picking. Also reads sheets back to JSON.

- **URL**: https://apify.com/s\_actors/google-sheets-import-export.md
- **Developed by:** [Superior Actors](https://apify.com/s_actors) (community)
- **Categories:** Integrations, Automation, Developer tools
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 1 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

Pay per event

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 Import & Export

Send any **Apify dataset or JSON to Google Sheets**, and read sheets back to JSON. Append new rows, **update existing rows by a unique key**, or replace the whole tab. Made for scrapers that run on a schedule: connect it once as an integration and every run lands in your sheet.

**No Google login, no OAuth tokens that expire.** Share your sheet once with the Actor's e-mail and it keeps working.

#### Setup (1 minute, once per sheet)

1. Open your Google Sheet → **Share**
2. Add this e-mail as **Editor**:

```
import@sheets-sync-509808.iam.gserviceaccount.com
```

3. Paste the sheet link into **Google Sheet** and pick a dataset. Done.

If Google says the address has no Google account, share anyway: it is a service account, that's normal. If you forget to share, the run tells you exactly that.

#### Why this Actor

| | |
|---|---|
| 🔁 **Update rows by key** | `update` mode changes rows in place (same `url` or `id`) and adds new ones. Your own columns (notes, formulas) stay untouched |
| 🔐 **Nothing expires** | Access is a normal share, not an OAuth token. Scheduled runs don't die after a few weeks |
| 🛡 **Retries Google limits** | Rate limits (429) and Google outages are retried with backoff instead of failing the run |
| 🧮 **Values stay correct** | Numbers stay numbers, IDs keep leading zeros, big IDs don't get rounded, text starting with `=` is never run as a formula |
| 📅 **Tab per day** | Tab name `Prices {date}` creates a new tab every day |
| 🧹 **Duplicates skipped** | Rows whose key is already in the sheet are not added again (and not charged) |
| 🧩 **Clean columns** | Columns in the scraper's order, your column order kept, lists as `wifi, pool` in one cell, pick or drop columns |
| 📏 **Big data** | Written in chunks; the sheet is never half-empty during `replace`; clear error before writing if Google's 10M-cell limit would be hit |

#### Modes

| Mode | What it does | Typical use |
|---|---|---|
| `append` | Adds rows at the end. New fields become new columns at the right | Leads, new listings, a log of every run |
| `update` | Rows with the same unique key are overwritten, new keys added at the end | Price and stock monitoring, CRM-style lists |
| `replace` | Overwrites the tab with the new data | "Current state" dashboards |
| `read` | Sheet rows → dataset items (header row = field names) | Feed a sheet into another Actor or an AI agent |

#### Use it after a scraper (integration)

1. Open your scraper or task → **Integrations** → **Connect Actor or Task** → choose this Actor
2. Set the input:

```json
{
  "spreadsheetId": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit",
  "sheetName": "Results",
  "mode": "append",
  "deduplicateByField": "url",
  "datasetId": "{{resource.defaultDatasetId}}"
}
```

Every successful scraper run now adds only new rows to the sheet.

#### Examples

| Goal | Input |
|---|---|
| Daily price monitor, one row per product, always up to date | `"mode": "update", "deduplicateByField": "url"` |
| Price history, one tab per day | `"mode": "append", "sheetName": "Prices {date}"` |
| Price history in one tab | `"mode": "append", "addTimestamp": true` |
| Hotel rates by date | `"mode": "update", "deduplicateByField": "entityId,checkInDate"` |
| Only some columns, in your order | `"columnsOrder": ["name", "price", "url"], "onlyListedColumns": true` |
| Drop nested noise | `"excludeColumns": ["images", "reviews"]` |
| Send rows from code or an AI agent | `"rawData": [{"name": "A", "price": 10}]` |

#### Ready-made tasks

Open one, change the inputs, and run or schedule it:

- [Price Monitoring in Google Sheets: Update Rows by URL](https://apify.com/s_actors/google-sheets-import-export/examples/price-monitoring-google-sheets)
- [Export Apify Dataset to Google Sheets Daily (Tab per Day)](https://apify.com/s_actors/google-sheets-import-export/examples/daily-export-to-google-sheets)
- [Google Sheet to JSON API: Read Any Sheet](https://apify.com/s_actors/google-sheets-import-export/examples/google-sheet-to-json)
- [Google Maps Leads to Google Sheets Without Duplicates](https://apify.com/s_actors/google-sheets-import-export/examples/google-maps-leads-to-google-sheets)
- [Hotel Rate Tracker in Google Sheets: Daily Competitor Prices](https://apify.com/s_actors/google-sheets-import-export/examples/hotel-rates-to-google-sheets)
- [Flight Price Tracker in Google Sheets: Row per Route and Date](https://apify.com/s_actors/google-sheets-import-export/examples/flight-prices-to-google-sheets)
- [App Store and Google Play Rankings to Google Sheets Daily](https://apify.com/s_actors/google-sheets-import-export/examples/app-rankings-to-google-sheets)
- [JSON to Google Sheets via API or AI Agent: Upsert Rows](https://apify.com/s_actors/google-sheets-import-export/examples/json-to-google-sheets-api)
- [Amazon Price Tracker in Google Sheets: Update by ASIN](https://apify.com/s_actors/google-sheets-import-export/examples/amazon-price-tracker-google-sheets)
- [Google Rank Tracker in Google Sheets: Keyword Positions](https://apify.com/s_actors/google-sheets-import-export/examples/serp-rank-tracker-google-sheets)

#### Input

| Field | Description |
|---|---|
| `spreadsheetId` | Sheet link or ID. A link with `#gid=` selects that tab |
| `mode` | `append`, `update`, `replace` or `read` |
| `sheetName` | Tab name, created if missing. `{date}`, `{month}`, `{datetime}` are replaced (UTC) |
| `datasetId` | Source dataset. In integrations: `{{resource.defaultDatasetId}}` |
| `rawData` | JSON array of objects, or array of arrays with a header row first |
| `limit`, `offset` | Part of the dataset only |
| `deduplicateByField` | Unique key column(s), comma-separated |
| `columnsOrder`, `onlyListedColumns`, `excludeColumns` | Column selection and order. Nested fields use `/`: `address/city` |
| `arrayMode` | `join` (default), `columns` (`tags/0`, `tags/1`), or `json` |
| `addTimestamp` | Adds an `exportedAt` column with the run time |
| `parseValues` | Let Google interpret values like typed by hand (dates, formulas). Off by default |
| `serviceAccountKey` | Optional: your own service account JSON key instead of the shared e-mail |

Field names `spreadsheetId`, `mode`, `datasetId`, `rawData`, `deduplicateByField`, `columnsOrder` match the popular free Google Sheets actor, so switching usually means changing the Actor and sharing the sheet.

#### Output

Write modes save one summary item:

```json
{
  "status": "ok",
  "mode": "update",
  "sheetName": "Prices",
  "rowsAppended": 12,
  "rowsUpdated": 488,
  "duplicatesSkipped": 0,
  "columns": 18,
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/.../edit"
}
```

`read` mode saves one item per sheet row.

#### Pricing

| Event | Price |
|---|---|
| Run start | $0.005 |
| Row written (added or updated) or read | $0.01 per 1,000 rows |
| Skipped duplicates, empty runs | free |

A typical scraper-to-sheet sync of 500 rows costs about **$0.01**.

#### Limits

| Limit | Value |
|---|---|
| Cells per spreadsheet (Google) | 10,000,000. The run stops with a clear message before writing |
| Characters per cell (Google) | 50,000. Longer text is cut |
| `rawData` size | 9 MB (Apify input limit). For more, use a dataset |

#### FAQ

**Is my data safe?** The Actor can open only the sheets you share with it, and only while they are shared. Remove the e-mail from Share to revoke access. Data is not stored anywhere except your sheet and your Apify run.

**Can I use my own Google account instead?** Yes: create a service account in Google Cloud, paste its JSON key into `serviceAccountKey` (stored encrypted), and share the sheet with that account's e-mail.

**Does it work with Excel files in Drive?** Only native Google Sheets. Open the .xlsx and use File → Save as Google Sheets.

**Can an AI agent use it?** Yes, through the Apify MCP server: the agent passes rows in `rawData`. No OAuth screen to click through.

# Actor input Schema

## `spreadsheetId` (type: `string`):

Link to your Google Sheet (or just its ID). Share the sheet once with import@sheets-sync-509808.iam.gserviceaccount.com as Editor (Share → paste the e-mail → Editor). The prefilled link is our demo sheet: it lets you try the Actor, writes at most 50 rows into its "Demo" tab and replaces them every run. Use your own sheet for real work.

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

append: add rows at the end. update: rows with the same unique key are updated in place, new ones added (price and stock monitoring). replace: overwrite the tab. read: sheet → JSON dataset.

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

Tab to write to or read from. Created automatically if it doesn't exist. Use {date} for one tab per day, e.g. "Prices {date}". Leave empty for the first tab (or the tab in your link).

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

Apify dataset to import. As an integration after a scraper use {{resource.defaultDatasetId}}.

## `rawData` (type: `array`):

Instead of a dataset: an array of objects, or an array of arrays where the first array is the header. Handy for AI agents and API calls.

## `limit` (type: `integer`):

Take at most this many items from the dataset. Empty = all.

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

Skip this many items at the start of the dataset.

## `deduplicateByField` (type: `string`):

Column that identifies a row, e.g. url or id (several: "hotelId,checkInDate"). append: rows whose key is already in the sheet are skipped. update: rows with this key are updated in place.

## `columnsOrder` (type: `array`):

These columns come first, in this order; the rest follow in the order they appear in the data. Nested fields use "/", e.g. address/city.

## `onlyListedColumns` (type: `boolean`):

Write only the columns listed above and drop the rest.

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

Columns to leave out. A name also drops its nested fields: "offers" drops offers/0/price, offers/1/price...

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

How lists like \["wifi", "pool"] become cells.

## `addTimestamp` (type: `boolean`):

Adds the run time (UTC) to every row. Useful for price history with append.

## `formatHeader` (type: `boolean`):

Formats the header when the Actor creates it.

## `parseValues` (type: `boolean`):

Off (default): values are written exactly as they are: numbers as numbers, text as text, IDs keep leading zeros, and text starting with "=" is never run as a formula. On: Google interprets values like typed by hand (dates, formulas, percentages).

## `headerRow` (type: `integer`):

Row with column names when reading a sheet.

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

Paste the JSON key of your own Google Cloud service account to use it instead of the Actor's shared e-mail. Stored encrypted.

## Actor input object example

```json
{
  "spreadsheetId": "https://docs.google.com/spreadsheets/d/1XEl1x1BNcQrfP1ZdDyBtvshMn7Pa50-I6eWy6etH9wk/edit",
  "mode": "append",
  "rawData": [
    {
      "product": "Wireless Mouse",
      "price": 24.99,
      "currency": "USD",
      "inStock": true,
      "url": "https://example.com/mouse"
    },
    {
      "product": "USB-C Hub",
      "price": 39.5,
      "currency": "USD",
      "inStock": false,
      "url": "https://example.com/hub"
    },
    {
      "product": "Laptop Stand",
      "price": 29,
      "currency": "USD",
      "inStock": true,
      "url": "https://example.com/stand"
    }
  ],
  "offset": 0,
  "onlyListedColumns": false,
  "arrayMode": "join",
  "addTimestamp": false,
  "formatHeader": true,
  "parseValues": false,
  "headerRow": 1
}
```

# Actor output Schema

## `results` (type: `string`):

Summary of the import, or the rows read from the sheet.

# 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 = {
    "spreadsheetId": "https://docs.google.com/spreadsheets/d/1XEl1x1BNcQrfP1ZdDyBtvshMn7Pa50-I6eWy6etH9wk/edit",
    "rawData": [
        {
            "product": "Wireless Mouse",
            "price": 24.99,
            "currency": "USD",
            "inStock": true,
            "url": "https://example.com/mouse"
        },
        {
            "product": "USB-C Hub",
            "price": 39.5,
            "currency": "USD",
            "inStock": false,
            "url": "https://example.com/hub"
        },
        {
            "product": "Laptop Stand",
            "price": 29,
            "currency": "USD",
            "inStock": true,
            "url": "https://example.com/stand"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("s_actors/google-sheets-import-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 = {
    "spreadsheetId": "https://docs.google.com/spreadsheets/d/1XEl1x1BNcQrfP1ZdDyBtvshMn7Pa50-I6eWy6etH9wk/edit",
    "rawData": [
        {
            "product": "Wireless Mouse",
            "price": 24.99,
            "currency": "USD",
            "inStock": True,
            "url": "https://example.com/mouse",
        },
        {
            "product": "USB-C Hub",
            "price": 39.5,
            "currency": "USD",
            "inStock": False,
            "url": "https://example.com/hub",
        },
        {
            "product": "Laptop Stand",
            "price": 29,
            "currency": "USD",
            "inStock": True,
            "url": "https://example.com/stand",
        },
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("s_actors/google-sheets-import-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 '{
  "spreadsheetId": "https://docs.google.com/spreadsheets/d/1XEl1x1BNcQrfP1ZdDyBtvshMn7Pa50-I6eWy6etH9wk/edit",
  "rawData": [
    {
      "product": "Wireless Mouse",
      "price": 24.99,
      "currency": "USD",
      "inStock": true,
      "url": "https://example.com/mouse"
    },
    {
      "product": "USB-C Hub",
      "price": 39.5,
      "currency": "USD",
      "inStock": false,
      "url": "https://example.com/hub"
    },
    {
      "product": "Laptop Stand",
      "price": 29,
      "currency": "USD",
      "inStock": true,
      "url": "https://example.com/stand"
    }
  ]
}' |
apify call s_actors/google-sheets-import-export --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,s_actors/google-sheets-import-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/NlzLROj9kYblQps4W/builds/Y06p4hOMWmWtK3M5f/openapi.json
