# Google Sheets Export & Import — Reliable, Append & Dedupe (`tidydata/google-sheets-export-import`) Actor

Send any Apify dataset to Google Sheets (replace, append or append without duplicates) or import a sheet into a dataset. Service-account auth that doesn't expire, automatic retries on Google quotas, nested JSON flattened into columns, big datasets in chunks.

- **URL**: https://apify.com/tidydata/google-sheets-export-import.md
- **Developed by:** [tidydata](https://apify.com/tidydata) (community)
- **Categories:** Integrations, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.20 / 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 Export & Import — reliable, append & dedupe

Send **any Apify dataset to Google Sheets** in one run, or **import a sheet into a dataset**. No Google Cloud setup, no OAuth pop-ups that expire: **just share your spreadsheet with our email and run.**

- ✅ **Replace**, **Append**, or **Append without duplicates** (by key columns like `url` or `id`)
- ✅ **Nested JSON flattened** into columns (`price.value`, `address.city`); lists joined as text
- ✅ **Automatic retries** when Google rate-limits, big datasets written in chunks
- ✅ New columns are added at the end when appending, nothing gets overwritten
- ✅ Values written as plain data (RAW), so scraped text can never run as a formula
- ✅ **Import** any tab into a dataset (one row per sheet row, header = field names)
- ✅ You pay only for rows written or imported

### Setup (30 seconds)

1. Open your Google spreadsheet → **Share**.
2. Add **`tidydata@tidydata-sheets.iam.gserviceaccount.com`** as **Editor** (untick "Notify").
3. In this Actor: paste the spreadsheet URL, pick the dataset, choose a write mode, run.

🔒 **Privacy:** the first Apify account that uses a spreadsheet becomes its owner for this Actor; any other account is refused, even if it knows the URL. You can remove our email from the sheet at any time. Advanced users can paste their own service account key instead.

### Use it after another Actor (integration)

In your scraper's **Integrations** tab add this Actor and set `datasetId` to `{{resource.defaultDatasetId}}`. Every run then lands in your sheet automatically; use **Append without duplicates** to keep one growing, clean table.

### Output

Export: one summary row with the spreadsheet link, tab, rows written and columns. Import: one dataset row per sheet row.

```json
{
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/…/edit#gid=825613968",
  "sheetName": "Apify",
  "writeMode": "replace",
  "rowsWritten": 47,
  "columns": 16
}
```

### Pricing

Pay per row written or imported. Duplicates skipped are free. Running without a spreadsheet shows a free preview of how your data becomes columns.

### Limits

Google Sheets holds up to 10 million cells per spreadsheet and 50,000 characters per cell (longer text is truncated and marked).

# Actor input Schema

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

Export: send an Apify dataset to a Google Sheet. Import: read a Google Sheet into this run's dataset.

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

The Google Sheets link (https://docs.google.com/spreadsheets/d/…) or just its ID. Share the spreadsheet as Editor with the email shown in the README. The first Apify account that uses a spreadsheet becomes its owner for this Actor, so nobody else can read or write it through here.

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

Tab (worksheet) to write to or read from. Created automatically on export if it doesn't exist.

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

The Apify dataset to export. Pick it from your storages or paste its ID. When this Actor runs as an integration after another Actor, use {{resource.defaultDatasetId}}.

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

Replace: clear the tab and write the dataset. Append: add rows under the existing ones (new columns are added at the end). Append without duplicates: like Append, but skips rows whose key columns already exist in the sheet.

## `dedupeKeys` (type: `array`):

Columns that identify a row (e.g. url, or id). Only used with 'Append without duplicates'. Use dot names for nested fields, e.g. author.id.

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

Only export these columns, in this order. Leave empty to export all columns.

## `flatten` (type: `boolean`):

Turn nested objects into columns (address.city, address.zip). Lists of simple values are joined with ', '; lists of objects are kept as JSON text.

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

Stop after this many rows (protects your budget). Google Sheets holds at most 10 million cells per spreadsheet.

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

Optional, for advanced users. Leave empty to use ours: just share your spreadsheet with our email. If you prefer your own Google Cloud service account, paste its full JSON key here (stored encrypted) and share the spreadsheet with that account instead.

## Actor input object example

```json
{
  "mode": "export",
  "sheetName": "Apify",
  "writeMode": "replace",
  "flatten": true,
  "maxRows": 100000
}
```

# Actor output Schema

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

Export: a summary with the sheet link and rows written. Import: one row per sheet row.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("tidydata/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 = {}

# Run the Actor and wait for it to finish
run = client.actor("tidydata/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 '{}' |
apify call tidydata/google-sheets-export-import --silent --output-dataset

```

## MCP server setup

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