# Google Sheets Export: datasets to your sheet, on your own quota (`somethingelseenirely/google-sheets-export`) Actor

Appends or replaces Apify dataset rows in a Google Sheet through your own service account, so runs use your own Google quota and retry when Google asks them to slow down. Skips duplicates, flattens nested data, and never runs formulas from scraped text.

- **URL**: https://apify.com/somethingelseenirely/google-sheets-export.md
- **Developed by:** [Something Else Entirely](https://apify.com/somethingelseenirely) (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.03 / 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/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: datasets into your spreadsheet, on your own Google quota

Send any Apify dataset, or a list of JSON objects, into a Google Sheet. Append new rows below
the old ones, skipping rows you already have, or replace the sheet's contents. The tool works
through your own Google service account, so it uses your own per-minute quota instead of one
shared by every user, and it waits and retries when Google asks it to slow down.

### What it does

- **Append** (default): adds the rows under the existing ones. New fields become new columns at
  the right, and existing columns keep their place.
- **Skip duplicates:** with `deduplicateByField`, a row whose value in that field is already in
  the sheet is left out. Schedule the tool after a scraper and only new items arrive.
- **Replace:** clears the sheet's values and writes the header and rows from the top.
- **Nested data** becomes columns named with slashes, such as `address/city`. A list of plain
  values goes into one cell, separated by commas; a list of objects goes into one cell as JSON.
- **Values are written as they are.** Text that looks like a formula, such as `=IMPORTXML(...)`,
  stays text, so a scraped page cannot run formulas in your sheet. Numbers and true/false stay
  numbers and booleans.

### Setting up access, once (about ten minutes)

1. In the [Google Cloud console](https://console.cloud.google.com/), create a project, or pick
   one you have.
2. Under **APIs & Services → Library**, turn on the **Google Sheets API**.
3. Under **IAM & Admin → Service Accounts**, create a service account. It needs no roles.
4. Open it, go to **Keys → Add key → Create new key → JSON**, and keep the file that downloads.
5. Open your spreadsheet, click **Share**, and add the service account's address (it ends in
   `iam.gserviceaccount.com`) as an **Editor**.
6. Paste the whole key file into the tool's **Service account key** field. Apify stores it
   encrypted.

The key reaches only Google: it is used to get a token from Google's own address, and the token
is sent only to the Sheets API. Nothing else is done with it, and it is never logged.

### Input

| Field | What it does | Default |
| --- | --- | --- |
| `spreadsheet` | The spreadsheet's address or ID | Required |
| `sheetName` | The tab to write to; created if it does not exist | The first tab |
| `datasetId` | The Apify dataset to export | One of these two |
| `rawData` | A JSON list of objects to export instead | |
| `mode` | `append` or `replace` | `append` |
| `columns` | Fields to write, in this order; others are left out | Every field |
| `deduplicateByField` | Skip a row whose value in this field is already in the sheet | None |
| `maxRows` | Write at most this many rows | Every row |
| `serviceAccountKey` | The service account's JSON key | Required |

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/1AbC.../edit",
  "sheetName": "Leads",
  "datasetId": "YOUR_DATASET_ID",
  "mode": "append",
  "deduplicateByField": "url"
}
```

### Output

The rows land in your sheet. The run's dataset gets one summary row:

```json
{
  "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1AbC.../edit#gid=0",
  "sheet": "Leads",
  "mode": "append",
  "rowsWritten": 120,
  "duplicatesSkipped": 37,
  "rowsLeftOverBudget": 0,
  "columns": ["url", "title", "price"]
}
```

### Good to know

- **Google's limits:** a spreadsheet holds at most 10 million cells, and a cell at most 50,000
  characters. The tool checks the cell count before it writes anything, and shortens longer
  cells.
- **Your data stays yours.** The tool reads your dataset with your own Apify access, writes it
  to your sheet, and keeps nothing. Rows are not logged.
- **If Google stops answering midway,** the rows already written stay in the sheet, the run says
  how many, and only those are charged.

### Pricing

$0.00005 per row written, so 1,000 rows cost $0.05. The header, skipped duplicates and rows
Google did not accept cost nothing.

# Actor input Schema

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

The spreadsheet's address, or just its ID. Share it with the service account as an Editor first.

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

The tab to write to. It is created if it does not exist. Empty means the first tab.

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

The Apify dataset to export, for example from a scraper's run. Give this or the JSON list below.

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

Rows to export instead of a dataset, as a list of objects.

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

Append adds the rows below the tab's existing rows. Replace clears the tab first.

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

Fields to write, in this order. Nested fields are named with slashes, such as address/city. Empty means every field.

## `deduplicateByField` (type: `string`):

Leave out a row whose value in this field is already in the tab, or earlier in this run. For example url.

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

Write at most this many rows. Empty means every row, up to 250,000.

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

The whole JSON key file of your Google service account. Stored encrypted. The README shows how to create one in about ten minutes.

## Actor input object example

```json
{
  "mode": "append"
}
```

# Actor output Schema

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

One row with the spreadsheet, tab and number of rows written.

# 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("somethingelseenirely/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 = {}

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

```

## MCP server setup

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