# Google Sheets Export & Import: Append, Upsert, Dedupe (`weav3rx/google-sheets-export-import`) Actor

Send any Apify dataset, JSON or CSV to Google Sheets and read sheets back as JSON. True append that never moves your columns, upsert by key column (no duplicates), replace, automatic retries on Google limits. Just share your sheet with our robot; no login that expires.

- **URL**: https://apify.com/weav3rx/google-sheets-export-import.md
- **Developed by:** [Roman Golovko](https://apify.com/weav3rx) (community)
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.10 / 1,000 rowscraps

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 Export & Import: Append, Upsert, Dedupe

**Send any data to Google Sheets, and read sheets back as JSON, without a Google login that keeps expiring.** Export an Apify dataset (for example the results of any scraper), a JSON array or a CSV file into a sheet with **true append**, **upsert by key** (update existing rows, add new ones, no duplicates) or **replace**. Or import a sheet into JSON.

### Setup in 20 seconds

1. Open your Google Sheet and click **Share**.
2. Add the robot's e-mail **`sheets-robot@calm-scarab-515602-k6.iam.gserviceaccount.com`** as an **Editor** (Viewer is enough for import).
3. Paste the sheet's link into the Actor and run.

That's it. No "Connect Google account", no tokens that expire. You can remove the robot from the sheet any time.

### Why this one

- ➕ **True append.** New rows go to the end. Your existing columns never move; new fields from your data become new columns on the right.
- 🔁 **Upsert by key (no duplicates).** Choose a key column like `url`, `id` or `email`: rows with the same key are updated in place, new keys are added. Perfect for daily scrapers feeding one sheet. Composite keys work too.
- 🧹 **Replace** clears the sheet and writes fresh data when you want a clean snapshot.
- 📥 **Import** reads a sheet into JSON (header row = field names), ready for other Actors and automations.
- 🛡️ **Doesn't fail on Google limits.** Google allows ~60 sheet operations per minute. When that's hit, the Actor waits and retries instead of failing and losing your data. Large exports are sent in efficient batches.
- 🧯 **Safe by default.** Text is written exactly as is, so scraped text starting with `=` can't turn into a formula in your sheet (no formula injection). Turn on *Let Google parse values* if you want dates and formulas interpreted.
- 🧩 **Nested data handled.** `{ "address": { "city": "Berlin" } }` becomes an `address.city` column; lists become readable text.
- ✍️ **Clear errors.** If the sheet isn't shared, the run tells you exactly which e-mail to share it with.

### Typical uses

- **Scraper → Sheet every day:** add this Actor as an integration to any Actor run ("on run succeeded"), pass the run's dataset, and use **upsert** on `url`, so your sheet always has the latest data without duplicates.
- **Lead lists:** append new leads, update existing ones by e-mail.
- **Price monitoring:** upsert products by URL to keep current prices.
- **Sheet as input:** import a list of URLs/keywords you maintain in Sheets and feed it to another Actor.

### Input

| Field | What it does |
|---|---|
| Spreadsheet | Link to the sheet (or its ID). A `#gid=` in the link selects that tab. |
| Mode | `append`, `upsert`, `replace` or `import` |
| Sheet (tab) name | Optional; created automatically for export if missing |
| Data | Pick one: an Apify dataset, pasted JSON, or a JSON/CSV URL |
| Key column(s) | For upsert, e.g. `url` |
| Column order | Optional fields to put first; *Only the columns listed* writes just those |
| Let Google parse values | Off by default (safe); on = dates/formulas interpreted |

### Output

Export writes a summary to the dataset and to `OUTPUT`:

```json
{
  "mode": "upsert",
  "spreadsheet": "Competitor prices",
  "sheet": "Products",
  "sheetUrl": "https://docs.google.com/spreadsheets/d/.../edit#gid=0",
  "rowsAppended": 42,
  "rowsUpdated": 958,
  "rowsSkippedWithoutKey": 0,
  "newColumns": ["discount"]
}
```

Import returns one item per row, keyed by the header row.

### FAQ

**Is my data safe?** The robot can only open spreadsheets you explicitly share with it, and only while they're shared. Data passes through your own Apify run and isn't stored anywhere else.

**Can I use my own Google service account?** Yes: paste its JSON key under *Advanced*, and share the sheet with that account's e-mail instead.

**What are the limits?** Google Sheets allows up to 10 million cells per spreadsheet and ~60 operations per minute per account; the Actor batches and retries to stay within them.

**Why is a column called `Column 3`?** On import, empty header cells get a generic name so no data is lost.

Need another mode or found a bug? Open an issue on the **Issues** tab.

# Actor input Schema

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

Link to your Google Sheet (or its ID). First click Share in the sheet and add sheets-robot@calm-scarab-515602-k6.iam.gserviceaccount.com as an Editor (Viewer is enough for import).

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

Append adds rows at the end. Upsert updates rows whose key column matches and appends the rest (no duplicates). Replace clears the sheet and writes fresh data. Import reads the sheet into the dataset as JSON.

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

Tab to use. Leave empty for the tab in your link (#gid) or the first tab. For export, a missing tab is created.

## `dataset` (type: `string`):

Pick a dataset to export, e.g. the results of another Actor run. In integrations, use the run's default dataset ID.

## `jsonData` (type: `array`):

Or paste data directly: an array of objects, or an array of arrays with a header row first.

## `dataUrl` (type: `string`):

Or a public link to a JSON array or a CSV file.

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

Field(s) that identify a row, e.g. url, id or email. Rows with the same key are updated instead of duplicated. Several fields = combined key.

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

Optional. Fields to put first, in this order (nested fields use dots, e.g. address.city). Existing sheet columns always keep their position.

## `onlySelectedColumns` (type: `boolean`):

Write only the fields listed in Column order (plus columns that already exist in the sheet).

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

Off (recommended): text is written exactly as is, so scraped text starting with = can't turn into a formula. On: Google interprets values like you typed them (dates, percentages, formulas).

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

Upper limit of rows written (export) or read (import) in one run.

## `serviceAccountJson` (type: `string`):

Only if you prefer your own robot account: paste the whole service-account .json key. Then share the sheet with that account's e-mail instead.

## Actor input object example

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/1JujAbUQvG5VQPtH1RSvJ5NYSJC4Ol37gUBshfTpXyLM/edit",
  "mode": "import",
  "onlySelectedColumns": false,
  "parseValues": false,
  "maxRows": 1000000
}
```

# Actor output Schema

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

Export: summary (rows appended, updated, skipped, new columns, sheet link). Import: the sheet rows as JSON objects keyed by the header row.

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

The same summary as a single JSON record.

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

// Run the Actor and wait for it to finish
const run = await client.actor("weav3rx/google-sheets-export-import").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 = {
    "spreadsheet": "https://docs.google.com/spreadsheets/d/1JujAbUQvG5VQPtH1RSvJ5NYSJC4Ol37gUBshfTpXyLM/edit",
    "mode": "import",
}

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

```

## MCP server setup

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

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/XERonC2hvA50Lj9pi/builds/OKpFJ5EvJNoLTHC1r/openapi.json
