# Google Sheets Export: send any Apify dataset to a spreadsheet (`bosco_labs/sheets-export`) Actor

Export an Apify dataset to Google Sheets after every scraper run (add it as an integration) or on demand: replace a tab or append rows, nested fields as columns, your header kept. Signs in with a Google service account key, no expiring OAuth; retries Google rate limits. $0.15 per 1,000 rows.

- **URL**: https://apify.com/bosco_labs/sheets-export.md
- **Developed by:** [Bosco Labs](https://apify.com/bosco_labs) (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.15 / 1,000 row exporteds

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: send any Apify dataset to a spreadsheet

**Export any Apify dataset to Google Sheets** in one run: the results of any scraper go
straight into your spreadsheet, as a fresh copy (replace) or added below what's already there
(append). For anyone who reports, shares or post-processes scraped data in Sheets. Nested
fields become their own columns, appends keep your header, and Google's rate limits are
retried automatically instead of failing the run.

**Built for schedules:** it signs in with a Google service account key, not a Google login
that expires, so a daily or hourly schedule keeps exporting without re-authorizing.

**Pricing (pay per event):** $0.00015 per row exported ($0.15 per 1,000 rows). No start fee;
the run stops at your max charge limit.

### Setup: connect your sheet (2 minutes, once)

The Actor writes with a Google **service account**: a robot account in your own Google Cloud
project that can only touch the sheets you share with it. You never give it your Google
password.

1. Open [console.cloud.google.com](https://console.cloud.google.com/) and create a project
   (or pick an existing one).
2. Go to **APIs & Services > Library**, search **Google Sheets API**, and click **Enable**.
3. Go to **IAM & Admin > Service Accounts > Create service account**. Any name works, e.g.
   `apify-sheets`. Skip the optional role and access steps and click **Done**.
4. Open the new service account, tab **Keys > Add key > Create new key > JSON**. A `.json` file
   downloads.
5. Open your spreadsheet, click **Share**, paste the service account's email (the
   `client_email` in the file, like `apify-sheets@your-project.iam.gserviceaccount.com`), give
   it **Editor**, untick "Notify people", and share.
6. In this Actor's input, paste the **whole content** of the `.json` file into
   **Service account key**. It is stored encrypted as a secret input.

If your organization blocks key creation (policy `iam.disableServiceAccountKeyCreation`), ask
your Google Workspace admin, or use a personal Google account.

### Input

```json
{
  "datasetId": "aBcD1234efGH5678i",
  "spreadsheetId": "1AbCdEfGhIjKlMnOpQrStUvWxYz0123456789",
  "sheetName": "Leads",
  "mode": "append",
  "serviceAccountJson": "{ \"type\": \"service_account\", ... }",
  "fields": ["name", "address.city", "phone", "website"]
}
```

| Field | Meaning |
|---|---|
| `datasetId` | The Apify dataset to export (required for an export) |
| `spreadsheetId` | From the sheet URL: `docs.google.com/spreadsheets/d/<ID>/edit` (required for an export) |
| `sheetName` | Tab to write to, created if missing. Empty = the first tab (any language) |
| `mode` | `replace` (default) clears the tab first; `append` adds rows below existing data |
| `serviceAccountJson` | The service account's JSON key (required for an export, secret) |
| `fields` | Only these columns, in this order. Empty = all fields |

**Free preview:** without `spreadsheetId` or `serviceAccountJson` the run writes nothing and charges nothing: it puts the first 10 rows of your dataset (or of a small sample, without `datasetId`) in its own dataset, exactly as they would land in the sheet.

### Output

A dataset item like

```json
{"name": "Café Central", "address": {"city": "Vienna", "zip": "1010"}, "tags": ["coffee", "cake"], "rating": 4.6}
```

becomes this row:

| name | address.city | address.zip | tags | rating |
|---|---|---|---|---|
| Café Central | Vienna | 1010 | \["coffee", "cake"] | 4.6 |

- Nested objects become `parent.child` columns; arrays are written as JSON text.
- Numbers and booleans stay numbers and booleans; missing values are empty cells.
- Values are written as plain values, never as formulas, so scraped text starting with `=`
  can't run inside your sheet.
- **Append mode:** your existing header row is kept as is. Columns the sheet doesn't have yet
  are added to the right.

The run's key-value store gets an `OUTPUT` record:

```json
{"spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1AbC...", "sheetName": "Leads", "rowsWritten": 1250, "columns": ["name", "address.city", "phone", "website"]}
```

### Use cases

- **Scraper to Sheets after every run:** add this Actor as an integration on your scraper's
  task, pass the run's default dataset ID, and use `append` to build a growing sheet.
- **Client reports:** a fixed tab that's replaced with fresh results every day.
- **Lead lists for sales teams:** only the columns they need, in the order they need.
- **Hand-off to no-code tools:** Looker Studio, Zapier or Make read from the sheet.

### Use with AI agents (MCP)

Agents can call this Actor as a tool through the
[Apify MCP server](https://github.com/apify/apify-mcp-server). Add this server URL to your MCP
client (Claude, Cursor, VS Code, ...):

```text
https://mcp.apify.com?tools=bosco_labs/sheets-export
```

It loads this Actor as a tool, plus the tools that read its results (`get-actor-run`,
`get-dataset-items`). The hosted server signs you in with OAuth, or accepts your Apify token as
`Authorization: Bearer <APIFY_TOKEN>`. On the default server (`https://mcp.apify.com`), agents
can also find this Actor with `search-actors` and run it with `call-actor`.

Example prompts this Actor answers:

- *"Put the results of my last Google Maps run into the 'Leads' tab of my spreadsheet, only name, phone and website."*
- *"Replace the 'Daily' tab with today's scraper results."*
- *"Append this week's new listings below the existing rows."*

For the first one, the agent passes:

```json
{"datasetId": "<dataset ID>", "spreadsheetId": "<spreadsheet ID>", "sheetName": "Leads", "mode": "append", "serviceAccountJson": "<service account JSON key>", "fields": ["title", "phone", "website"]}
```

**Output for agents:** the run writes no dataset rows; its `OUTPUT` record in the key-value
store holds `spreadsheetUrl`, `sheetName`, `rowsWritten` and `columns`, so the agent can link
the sheet. `serviceAccountJson` is required, so the key passes through the agent's tool call:
use a service account that is shared only on the sheets the agent may write to.

**Cost:** $0.00015 per row exported, billed to the Apify account the MCP server is signed in with.

### FAQ

**I get "Google returned 403" or "404".** The sheet isn't shared with the service account, or
the spreadsheet ID is wrong. The error message shows the exact email to share it with, as
Editor.

**"Google Sheets API has not been used in project ... or it is disabled".** Do setup step 2 in
the same Google Cloud project as the key.

**How many rows can I export?** Google allows 10 million cells per spreadsheet (rows x
columns, across all tabs). Rows are sent in batches of up to 5,000 rows or 2 MB.

**What happens on rate limits?** Google answers 429 when you write too fast. The Actor waits
and retries (up to 5 times, after 1, 2, 4, 8 and 16 seconds), also on Google server errors.

**Very long text?** Google rejects cells over 50,000 characters, so longer values are cut at
50,000 characters instead of failing the run.

**Does replace mode delete formatting?** No, only cell values are cleared. Formatting, charts
and other tabs stay.

**Is my key safe?** It's a secret input (encrypted by Apify), it's only used to request a
Sheets access token from Google, and it's never logged or saved. Delete the key in Google Cloud
whenever you want to revoke access.

# Actor input Schema

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

Apify dataset ID to export, e.g. "aBcD1234efGH5678i": usually the defaultDatasetId of a scraper run (Storage tab).

## `spreadsheetId` (type: `string`):

Google spreadsheet ID: the part between /d/ and /edit in the sheet URL docs.google.com/spreadsheets/d/<ID>/edit, e.g. "1AbCdEfGhIjKlMnOpQrStUvWxYz0123456789". The full sheet URL also works. Without it (or without serviceAccountJson) the run is a free preview: the first rows as they would be written, nothing exported.

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

Name of the tab to write to, e.g. "Leads". Created if it doesn't exist. Leave empty to use the first tab (whatever it is called, e.g. "Sheet1" or "Blad1").

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

"replace" (default) clears the tab's values and writes the dataset; "append" adds rows below the existing data, keeps your header and adds any new columns on the right.

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

Full contents of a Google service account JSON key file (secret input, stored encrypted). Share the spreadsheet with that account's client_email as Editor first. See the README for the 2-minute setup. E.g. the whole file, starting with {"type": "service_account", ...}.

## `fields` (type: `array`):

Columns to export, in this order; nested fields use dots, e.g. \["name", "address.city", "phone"]. Empty = all fields.

## Actor input object example

```json
{
  "mode": "replace"
}
```

# Actor output Schema

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

// Run the Actor and wait for it to finish
const run = await client.actor("bosco_labs/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("bosco_labs/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 bosco_labs/sheets-export --silent --output-dataset

```

## MCP server setup

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