# Google Sheets Import & Export (No OAuth, Reliable) (`stubborn_otter/google-sheets-import-export`) Actor

Append, replace, upsert or read Google Sheets from any dataset. No Google sign-in to expire: just share the sheet. Chunked writes with retries, automatic new columns and clear error messages.

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

## Pricing

from $0.05 / 1,000 row writtens

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 (No OAuth, Reliable)

Send any Apify dataset to a Google Sheet, or read a Sheet into a dataset, **without connecting your Google account**. There's no sign-in to expire, so scheduled runs keep working.

### Why this Actor

| Common problem | What this Actor does |
|---|---|
| Google sign-in gets blocked or expires, breaking scheduled runs | **No sign-in.** You share the sheet with our service account, once. |
| Big uploads fail with "Internal error encountered" | Writes in **chunks with automatic retries**, and shrinks the chunks if Google keeps refusing. |
| "Requested writing within range…" errors | **Adds rows and columns to the tab** before writing. |
| Hitting Google's cell limit halfway through | **Checks the 10-million-cell limit first** and tells you what to do. |
| Append mode wiping existing data | Append **never deletes anything** (covered by an automated test). |
| "Spreadsheet ID must be 44 characters" | Paste **any Sheets link or ID**. |
| Can't choose a tab | Type a **tab name**; it's created if it doesn't exist. |
| AI agents (MCP) can't complete a Google sign-in | Works from Claude, ChatGPT and other agents: no sign-in step. |

### Set up in 1 minute

1. Open your Google Sheet and click **Share**.
2. Add **`sheets-bot@stubborn-otter-sheets.iam.gserviceaccount.com`** as an **Editor**.
3. Run the Actor with your sheet's link.

The service account can only open sheets you've shared with it. Rows pass straight from your dataset to your sheet; nothing is stored. Prefer your own Google Cloud account? Paste your own service account key into **Your own service account key**, and share the sheet with that account instead.

### Modes

- **Append** (default): adds rows after your existing data, or at the top under the header. New fields become new columns automatically.
- **Replace**: clears the tab, then writes the header and rows.
- **Upsert**: rows whose **key column(s)** match (e.g. `url`, `id`) are updated, and the rest are appended. Columns you don't send are kept as they are. Perfect for scheduled scrapers that re-check the same items.
- **Read**: exports the tab to this run's dataset (the header row becomes field names).

Nested data is flattened (`price.value`, `seller.name`), lists of values are joined with commas, and lists of objects are stored as JSON text.

### Use it after another Actor (integration)

In the other Actor's **Integrations** tab, add this Actor and set:

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/…/edit",
  "datasetId": "{{resource.defaultDatasetId}}",
  "mode": "upsert",
  "keyColumns": ["url"]
}
```

Every time the scraper finishes, its results land in your sheet, with duplicates updated instead of repeated.

### Input examples

Append pasted rows to a tab called "Leads":

```json
{ "spreadsheet": "https://docs.google.com/spreadsheets/d/…/edit", "sheetName": "Leads",
  "data": [{ "company": "Example Co", "url": "https://example.com" }] }
```

Read a tab:

```json
{ "spreadsheet": "https://docs.google.com/spreadsheets/d/…/edit", "mode": "read", "sheetName": "Prices" }
```

### Output

A summary is saved to the run's key-value store as `OUTPUT`:

```json
{ "mode": "upsert", "sheet": "Leads", "rowsAppended": 120, "rowsUpdated": 880, "columnsAdded": ["rating"],
  "duplicatesInInput": 3, "url": "https://docs.google.com/spreadsheets/d/…/edit" }
```

In **read** mode, the rows are in the run's dataset.

### Pricing

Pay per event: a small charge per run, plus a charge per row written or read (see the Pricing tab). **Dry run** mode checks everything and reports what would change, for free. The Actor respects your maximum cost per run: if the limit allows only part of the data, it writes the first rows that fit and tells you.

### Errors, in plain English

Every failure ends with one sentence saying what to fix. For example:

- *"This sheet isn't shared with sheets-bot@…. Open the sheet, click Share, add it as Editor, then run again."*
- *"Tab 'Leeds' not found. Tabs in this spreadsheet: Leads, Archive"* (in read mode; other modes create the tab)
- *"Dataset 'abc' has no items, so there's nothing to write. If this runs after another Actor, check that run produced results."*
- *"This would make the spreadsheet 10,400,000 cells, over Google's limit…"*

### Limits

- Google allows 10,000,000 cells per spreadsheet, counting every tab's full grid (including empty cells).
- Text starting with `=` is written as plain text by default, so scraped data can't run as formulas. Choose "As if typed" if you want formulas and dates interpreted.

# Actor input Schema

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

Paste your sheet's address from the browser (any Google Sheets link or ID works). The example link is our demo sheet: replace it with yours. Before the first run, click Share in your sheet and add this Actor's service account email (shown in the README) as Editor.

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

Append adds rows after the existing data. Replace clears the tab first. Upsert updates rows whose key column(s) match and appends the rest. Read exports the tab to this run's dataset.

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

Which tab to use. Created automatically if it doesn't exist. Leave empty for the tab in your link (or the first tab).

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

Pick the Apify dataset whose items become rows. In an integration (running after another Actor), set this to {{resource.defaultDatasetId}}.

## `data` (type: `array`):

A list of objects, one per row. Nested fields become columns like 'price.value'.

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

Columns that identify a row, e.g. 'url' or 'id'. Only used in upsert mode.

## `insertAt` (type: `string`):

Append below the existing rows (default) or at the top, right under the header row. Only used in append mode.

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

Limit and order the columns written. Leave empty to write every field.

## `valueInputOption` (type: `string`):

Plain values (default) write text exactly as given, so scraped text starting with '=' can't run as a formula. 'As if typed' lets Google interpret formulas, dates and numbers.

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

Advanced: paste a Google Cloud service account JSON key to use your own account instead of ours. Share the sheet with that account's email.

## `dryRun` (type: `boolean`):

Check everything and report what would change, without writing.

## Actor input object example

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/1-H3xyI7JBi0COcla-Q1LbviOfGzqlMM1iqcsUjBGeDI/edit",
  "mode": "append",
  "data": [
    {
      "name": "Example Co",
      "url": "https://example.com",
      "price": 19.99
    }
  ],
  "insertAt": "bottom",
  "valueInputOption": "RAW",
  "dryRun": false
}
```

# Actor output Schema

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

What changed: rows appended or updated, columns added, the tab name and a link to the sheet.

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

Read mode: every row of the tab as an item (the header row becomes field names). Write modes: one item with the run summary.

# 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/1-H3xyI7JBi0COcla-Q1LbviOfGzqlMM1iqcsUjBGeDI/edit",
    "data": [
        {
            "name": "Example Co",
            "url": "https://example.com",
            "price": 19.99
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("stubborn_otter/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 = {
    "spreadsheet": "https://docs.google.com/spreadsheets/d/1-H3xyI7JBi0COcla-Q1LbviOfGzqlMM1iqcsUjBGeDI/edit",
    "data": [{
            "name": "Example Co",
            "url": "https://example.com",
            "price": 19.99,
        }],
}

# Run the Actor and wait for it to finish
run = client.actor("stubborn_otter/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 '{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/1-H3xyI7JBi0COcla-Q1LbviOfGzqlMM1iqcsUjBGeDI/edit",
  "data": [
    {
      "name": "Example Co",
      "url": "https://example.com",
      "price": 19.99
    }
  ]
}' |
apify call stubborn_otter/google-sheets-import-export --silent --output-dataset

```

## MCP server setup

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