# Google Sheets Export: Append, Replace & Upsert (No OAuth) (`southern-data/google-sheets-export`) Actor

Write an Apify dataset (or JSON) to a Google Sheet using a service account you share the sheet with. Append really appends, replace replaces, upsert matches a key column. No OAuth popup and no tokens that expire.

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

## Pricing

from $0.16 / 1,000 row written or read (after 1,000 free)s

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: Append, Replace & Upsert (No OAuth)

Write an Apify dataset (or a JSON list) to a Google Sheet using a **service account you share the sheet with**. There is no OAuth consent screen and no refresh token that expires after six unused months.

- **append** adds rows after the existing data — it does not overwrite what is already there.
- **replace** clears the tab and writes the new header + rows.
- **upsert** updates rows that match a key column and appends the rest.
- **read** copies the tab back into this Actor’s dataset. Public/published sheets can be read without a key.

**Who it's for:** anyone who scrapes with Apify and wants the results in a Google Sheet that keeps working, without the OAuth connection that can break, and who needs rows appended or updated rather than the whole sheet overwritten.

### Use with AI agents (Apify MCP)

Agents on the [Apify MCP server](https://docs.apify.com/mcp) discover Store Actors with `search-actors` (title, name, description, username and this README) and then call `fetch-actor-details` for the input schema, output/dataset schema and pricing.

- **Actor name:** `southern-data/google-sheets-export`
- **Use it when:** you need to write an Apify dataset (or JSON) to a Google Sheet, or read a sheet back, using a Google service account you share the sheet with. No OAuth popup and no tokens that expire. `append` really appends; `replace` replaces; `upsert` matches a key column.
- **Main inputs:** `spreadsheetUrl`, `mode` (`append`, `replace`, `upsert` or `read`), a service account JSON (secret), and `datasetId` / `runId` / `items` / `itemsUrl` for writes.
- **Output:** write modes store a `RUN_SUMMARY` in the key-value store (rows written, charges). Read mode writes one dataset row per sheet row. If required input is missing, the Actor writes one explanatory dataset row and charges nothing, so the run is not left empty.

### Limits (read these first)

1. **You must share the spreadsheet with the service account email as Editor** (except public `mode=read`). If you skip that step, the run ends with a plain-English error naming the email to share with. Nothing is charged. The default input reads Google's public sample Class Data sheet (`mode=read`) and needs no key. If you try a write mode without a key, the run succeeds, nothing is charged, and one dataset row explains what to do next.
2. **No OAuth.** This Actor does not open a Google login popup and does not use your own Google user. That is intentional: the official Apify Google Sheets integration uses OAuth and is a common source of “can’t connect” failures.
3. **Values are written as raw text/numbers.** Cells that start with `=`, `+`, `-`, `@` or a tab are prefixed with a quote so scraped text cannot run `=IMPORTRANGE` or similar in your sheet.
4. **First 1,000 rows of each run are free.** After that you pay a small start fee plus a per-row fee. A typical “export this Actor’s dataset” job of a few hundred rows costs $0.
5. **Maximum 50,000 rows per run** (default cap 20,000). Google’s own spreadsheet cell limit still applies.
6. **Append uses the headers already in the sheet.** Extra fields on new items are ignored unless you replace the tab or start from an empty sheet (which writes headers from the data).
7. **Creating a service account is a one-time Google Cloud step** (about five minutes). See “Set up the service account” below.

### Quick start

Click **Try for free** to read Google's public sample Class Data sheet. No service account is needed for that read.

To write to your own sheet:

1. Create a Google Cloud service account, enable the **Google Sheets API**, and download a JSON key (steps below).
2. Share your spreadsheet with the `client_email` inside that JSON as **Editor**. You can uncheck “Notify people”.
3. Run:

```json
{
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/your-spreadsheet-id/edit",
  "mode": "append",
  "datasetId": "your-apify-dataset-id",
  "serviceAccountJson": "{ ... paste the JSON key ... }"
}
```

Replace the whole tab:

```json
{
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/your-spreadsheet-id/edit",
  "sheetName": "Leads",
  "mode": "replace",
  "datasetId": "your-apify-dataset-id",
  "serviceAccountJson": "{ ... }"
}
```

Update existing rows by email and append new ones:

```json
{
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/your-spreadsheet-id/edit",
  "mode": "upsert",
  "keyColumn": "email",
  "datasetId": "your-apify-dataset-id",
  "serviceAccountJson": "{ ... }"
}
```

### Set up the service account

1. Open [Google Cloud Console](https://console.cloud.google.com/), create or pick a project.
2. APIs & Services → Enable APIs → enable **Google Sheets API**.
3. IAM & Admin → Service accounts → Create. Download a JSON key.
4. Open the JSON and copy `client_email` (it looks like `sheets@your-project.iam.gserviceaccount.com`).
5. In Google Sheets, Share the spreadsheet with that email as Editor.

Store the JSON key in the Actor input as a secret, or as an Actor secret named `GOOGLE_SERVICE_ACCOUNT_JSON` if you run this yourself. Do not paste the key into a public README or a shared screenshot.

### Chaining after another Actor

After any southern-data (or other) Actor run, pick its default dataset in the **Dataset** field (or pass `datasetId` / `resource.defaultDatasetId`). Selecting the dataset — rather than only pasting an unrelated ID into a generic text box — is what lets this Actor read it under Apify’s limited-permission model.

### Pricing (pay per event)

| Event | Price | When |
|---|---|---|
| *(first 1,000 rows)* | $0 | Every run’s first 1,000 rows written or read are free, and there is no start fee |
| `actor-start` | $0.005 | Once per run, only if you go past 1,000 rows |
| `row` | $0.0002 | Each row after the first 1,000 |

**Store discount tiers:** free-plan and Bronze users pay the prices above. Silver gets 10% off and Gold (and higher) gets 20% off.

**Free:** invalid input (exit 0, $0), permission errors that name the email to share with, empty source data.

Examples: 500 rows → **$0**. 5,000 rows → **$0.005 + 4,000 × $0.0002 = $0.805**.

### Tips

- Keep `serviceAccountJson` marked secret in saved tasks.
- Use `mode=append` when you do not want a “replace wiped my sheet” surprise.
- Cap spend with `maxRows` and Apify’s `maxTotalChargeUsd`.
- Default memory is 512 MB.

### Self-test

Set `"selfTest": true` to run offline checks of append/replace/upsert planning, formula escaping, URL parsing and JWT signing. If a spreadsheet URL and service account are also provided (our private daily schedule does this), a one-row live write/read runs on the `SelfTest` tab. Leave `selfTest` off for normal use.

### FAQ

**How do I export an Apify dataset to Google Sheets?**

Create a Google Cloud service account, share your sheet with its email as Editor, then run this Actor with the sheet URL, the dataset (or run ID) and the service account JSON as a secret. Choose append, replace or upsert.

**What is the difference between append, replace and upsert?**

Append adds rows after the existing data. Replace clears the tab and writes new headers and rows. Upsert updates rows whose key column matches (for example email) and appends the rest.

**Why no OAuth?**

A service account has no consent screen and no refresh token that can expire after months of inactivity. The trade-off is a one-time Google Cloud setup of about five minutes.

**What does it cost?**

The first 1,000 rows of every run are free with no start fee. After that, $0.005 per run plus $0.0002 per row. 500 rows cost $0; 5,000 rows cost $0.805.

**What happens if I run the default example?**

The default input reads Google's public sample Class Data sheet (student name, class, major and so on) in `mode=read`, with no service account. You get the real rows from that sheet and are not charged. To write to your own sheet, switch to append, replace or upsert, paste your sheet URL and a service account key, and share the sheet with that account as Editor.

# Actor input Schema

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

The spreadsheet link from your browser (https://docs.google.com/spreadsheets/d/…/edit) or just the spreadsheet ID. The prefilled URL is Google's public sample Class Data sheet, which you can read with mode=read and no service account.

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

Which tab to read or write. Leave empty to use the first tab, or the tab from a #gid= in the URL.

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

append = add rows after the existing data (never overwrites). replace = clear the tab and write the new rows. upsert = update rows that match keyColumn and append the rest. read = copy the tab back into this Actor’s dataset.

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

Header name used to match existing rows, e.g. "productId" or "email". Required for upsert. Matching is case-insensitive on the header name.

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

The dataset produced by another Actor run. Pick it here (or pass its ID) so this Actor is allowed to read it. If you chain this Actor after another one, pass the previous run’s defaultDatasetId.

## `runId` (type: `string`):

If you have a run ID instead of a dataset ID, the Actor reads that run’s default dataset.

## `itemsUrl` (type: `string`):

A URL that returns a JSON array of objects (for example an Apify dataset items URL ending in /items?format=json).

## `items` (type: `array`):

Inline array of row objects. Useful for trying the Actor without another dataset. Prefer datasetId for real exports.

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

Paste the JSON key file of a Google Cloud service account that has the Sheets API enabled. Then share the spreadsheet with that account’s client_email as Editor. No OAuth popup, and the key does not expire after six unused months. Leave empty only for mode=read on a public sheet.

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

Hard cap on rows read from the source (or read back from the sheet). Default 20,000, maximum 50,000.

## `selfTest` (type: `boolean`):

Offline checks of append/replace/upsert planning, formula escaping, URL parsing and JWT signing. If a spreadsheet URL and service account are also provided, a one-row live write/read is run on the named tab (default SelfTest). Leave off for normal use.

## Actor input object example

```json
{
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit",
  "mode": "append",
  "items": [
    {
      "name": "Ada Lovelace",
      "email": "ada@example.com"
    },
    {
      "name": "Alan Turing",
      "email": "alan@example.com"
    }
  ],
  "maxRows": 20000,
  "selfTest": false
}
```

# Actor output Schema

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

In mode=read, one dataset row per non-empty sheet row.

## `runSummary` (type: `string`):

RUN_SUMMARY record: mode, sheet name, rows written or read, charged events, any input problem.

## `selfTest` (type: `string`):

SELF_TEST record: only present when the Actor runs with selfTest: true.

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

// Run the Actor and wait for it to finish
const run = await client.actor("southern-data/google-sheets-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 = {
    "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit",
    "mode": "read",
}

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

```

## MCP server setup

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