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

Send any Apify dataset or JSON to Google Sheets, or import a sheet into a dataset. Uses a Google service account, so it never breaks because an OAuth login expired. Append, replace, or append only new rows (dedupe by key). Auto-creates tabs and columns, flattens nested JSON.

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

## Pricing

from $0.20 / 1,000 row written or importeds

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

Send the results of any Apify Actor (or any JSON) to **Google Sheets**, or pull a sheet back into an Apify dataset.

This Actor signs in with a **Google service account** instead of a personal OAuth login. Personal logins expire and make scheduled runs fail; a service account key keeps working, so the export runs unattended every day.

### Features

- ➕ **Append**: add new rows to the end of a tab
- ♻️ **Replace**: clear the tab and write fresh data (daily snapshots)
- 🧹 **Append only new rows**: dedupe on one or more key columns (e.g. `url`, `id`), so scheduled scrapes never create duplicates
- 📥 **Import**: read a tab into a dataset (header row = field names), e.g. to feed URLs or keywords into another Actor
- 🗂️ **Auto-create tabs** and **auto-add new columns** when your data gets new fields
- 🪆 **Flattens nested JSON** (`seller.name`, `address.city`); lists become comma-separated text
- 🎯 Choose and order columns, limit rows
- 🔁 Retries Google's rate limits (429) and server errors automatically
- 🛡️ Writes values as raw text, so scraped text starting with `=` is never executed as a formula

### Use it as an integration (recommended)

1. Open the Actor whose results you want in Sheets (e.g. Google Maps Scraper).
2. Go to **Integrations → Add integration → Apify Actor**, pick this Actor.
3. Fill in the spreadsheet URL and the service account key. Leave **Source dataset** empty; the finished run's dataset is used automatically.

Every finished run now lands in your spreadsheet.

### 2-minute setup: Google service account

1. Go to [Google Cloud Console](https://console.cloud.google.com/) and create (or pick) a project.
2. **APIs & Services → Library → Google Sheets API → Enable**.
3. **IAM & Admin → Service Accounts → Create service account** (no roles needed).
4. Open the service account → **Keys → Add key → Create new key → JSON**. A `.json` file downloads.
5. Open your spreadsheet → **Share** → add the service account's email (`...@...iam.gserviceaccount.com`) as **Editor**.
6. Paste the whole content of the `.json` file into the **Google service account key** field. It is stored encrypted.

### Input

| Field | Description |
|---|---|
| `spreadsheet` | Spreadsheet URL or ID (required for export) |
| `serviceAccountJson` | Service account key JSON (required for export, secret) |
| `mode` | `append` (default), `replace`, `append-unique`, `import` |
| `sheetName` | Tab name, default `Sheet1`. Created if missing |
| `datasetId` | Dataset to export. Optional when used as an integration |
| `rawData` | JSON array to export instead of a dataset |
| `uniqueKeyColumns` | Key columns for `append-unique` |
| `columns` | Export only these columns, in this order |
| `flatten` | Flatten nested objects into dot-notation columns (default `true`) |
| `maxItems` | Row limit, `0` = all |

Example:

```json
{
    "spreadsheet": "https://docs.google.com/spreadsheets/d/1AbC.../edit",
    "serviceAccountJson": "{ \"type\": \"service_account\", ... }",
    "mode": "append-unique",
    "sheetName": "Leads",
    "uniqueKeyColumns": ["url"]
}
```

### Output

A summary is saved to the dataset (export modes) and to the `OUTPUT` record:

```json
{
    "status": "success",
    "mode": "append-unique",
    "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1AbC...",
    "sheetName": "Leads",
    "rowsProcessed": 120,
    "skippedDuplicates": 37,
    "rowsNotProcessedDueToMaxCost": 0,
    "finishedAt": "2026-11-23T14:00:00.000Z"
}
```

In `import` mode, each sheet row becomes one dataset item.

### Pricing

Pay per event: you are charged **per row written or imported**. Skipped duplicates are free. Use "Max cost per run" to cap spending; the Actor stops cleanly at the cap and reports how many rows were left out.

### Limits

- Google Sheets allows 10 million cells per spreadsheet. Use `columns` to keep wide datasets small.
- Cells longer than 50,000 characters are truncated (a Google Sheets limit).

### Free preview

Run the Actor with its default input (no key, placeholder spreadsheet) to see how your data would be flattened into columns. A preview writes nothing to Google Sheets and charges no rows. Pass `rawData` to preview your own JSON (first 10 items). If you set a real spreadsheet but no key, the run fails with a clear message instead.

### Troubleshooting

- **403 Permission denied**: share the spreadsheet with the service account email as Editor, and enable the Google Sheets API in the same Google Cloud project.
- **404 Not found**: check the spreadsheet URL/ID.
- **Unique key column not present**: the column name must match a field in your data (use dot notation for nested fields).

# Actor input Schema

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

The Google Sheets URL (https://docs.google.com/spreadsheets/d/...) or just its ID. Share the spreadsheet with your service account email as Editor.

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

Paste the whole JSON key file of a Google Cloud service account with the Google Sheets API enabled. Stored encrypted. See the README for a 2-minute setup. Required for real exports; without it (and with the placeholder spreadsheet) the run only shows a free preview.

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

append: add rows at the end. replace: clear the tab and write fresh. append-unique: add only rows whose key columns are not in the sheet yet. import: read the tab into this run's dataset.

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

Tab to write to or read from. Created automatically if it does not exist (export modes).

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

Dataset to export. When you add this Actor as an integration to another Actor, the finished run's dataset is used automatically.

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

Alternative to a dataset: a JSON array of objects to export.

## `uniqueKeyColumns` (type: `array`):

For append-unique: columns that identify a row, e.g. 'url' or 'id'. Rows whose key already exists in the sheet are skipped.

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

Only export these columns, in this order. Use dot notation for nested fields, e.g. 'address.city'. Empty = all fields.

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

Turn nested objects into columns like 'address.city'. Lists of simple values are joined with commas; other lists become JSON text.

## `maxItems` (type: `integer`):

Limit the number of rows exported or imported. 0 = no limit.

## Actor input object example

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit",
  "mode": "append",
  "sheetName": "Sheet1",
  "uniqueKeyColumns": [],
  "columns": [],
  "flatten": true,
  "maxItems": 0
}
```

# Actor output Schema

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

No description

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

No description

# 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/YOUR_SPREADSHEET_ID/edit"
};

// Run the Actor and wait for it to finish
const run = await client.actor("seungtaek94/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 = { "spreadsheet": "https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit" }

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

```

## MCP server setup

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