# Google Sheets Export & Live Dataset Sync (`abzalp/google-sheets-sync`) Actor

Automatically export Apify dataset results to Google Sheets in real-time. Append rows, deduplicate data, and automate scraping workflows with Google Drive.

- **URL**: https://apify.com/abzalp/google-sheets-sync.md
- **Developed by:** [Abdul Basit](https://apify.com/abzalp) (community)
- **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 synced rows

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/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 & Sync

[![Apify Store](https://img.shields.io/badge/Apify%20Store-Run%20Actor-FF9800?style=for-the-badge\&logo=apify\&logoColor=white)](https://apify.com/abzalp/google-sheets-sync)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](LICENSE)
[![Free Tier Supported](https://img.shields.io/badge/Free%20Tier-5%20USD%20Monthly-brightgreen?style=for-the-badge)](https://apify.com/abzalp/google-sheets-sync)

> 🚀 **[Run this Actor on Apify Store](https://apify.com/abzalp/google-sheets-sync)** — Instant cloud execution with zero setup, zero proxies needed, and free monthly credits.

Send any Apify dataset to a Google Sheet, and keep it up to date. Add new rows, update existing rows by a key such as `url`, or replace the whole tab. Duplicates are skipped, Google rate limits are retried automatically, and **you only pay for rows that were actually added or changed**.

**What you get**

- ✅ **Three write modes:** append, upsert (update by key, add the rest) and replace.
- ✅ **No duplicates:** set a key column like `url` and rows that already exist are never added twice.
- ✅ **Handles Google rate limits:** waits and retries up to 7 times before giving up with a clear message.
- ✅ **Works as an integration:** runs automatically after any scraper finishes and picks up its dataset.
- ✅ **Nested data becomes columns:** `address.city` becomes an `address/city` column, the same as Apify's CSV export.
- ✅ **Safe by default:** values are written as plain text, so a scraped value like `=IMPORTXML(...)` never runs as a formula.

### What does it cost?

This Actor uses pay-per-event pricing. You're charged a small fee per run start and per **row written** (added or changed). Rows that already match the sheet, and duplicates skipped by your key columns, are free. See the **Pricing** tab for current prices. You can set a maximum cost per run, and the Actor stops writing when it reaches it.

### Quick start

1. **Connect Google** (one time, about 3 minutes): create a service account key. Steps below.
2. **Share your sheet** with the service account's email address as **Editor**.
3. **Run the Actor:** paste the sheet URL and your key, pick a dataset, and choose a mode.

#### Set up a Google service account (one time)

1. Open **Google Cloud Console** and create a project, or pick an existing one.
2. Go to **APIs & Services → Library**, search for **Google Sheets API** and click **Enable**.
3. Go to **IAM & Admin → Service Accounts → Create service account**. Give it any name. You can skip the optional role steps.
4. Open the new service account, go to **Keys → Add key → Create new key → JSON**. A `.json` file downloads.
5. Open that file in a text editor, copy **everything**, and paste it into **Service account key (JSON)**. Apify stores it encrypted.
6. In the `.json` file, find `client_email` (it ends with `iam.gserviceaccount.com`). In Google Sheets, click **Share** and add that email as **Editor**.

> Your key belongs to your own Google Cloud project, so your quota is never shared with other users, and only sheets you explicitly share can be written to.
>
> If your company's Google Workspace blocks service account keys, ask your admin, or use a personal Google account.

*This Actor is independent. It isn't affiliated with, sponsored by or endorsed by Google. Google Sheets and Google Cloud are trademarks of Google LLC.*

### Write modes

| Mode | What happens | Typical use |
|---|---|---|
| **Append** | Adds rows below the existing data. With **Key columns** set, rows whose key already exists are skipped. | Daily scrapes where you want a growing list without duplicates |
| **Upsert** | Rows whose key matches are updated (only the columns in the new data), the rest are added. Needs **Key columns**. | Price or stock tracking, where the same product should stay on one row |
| **Replace** | Clears the tab and writes the dataset fresh. | Always showing the latest full snapshot |

New fields that appear later are added as new columns at the end. Columns you added yourself are kept in append and upsert mode.

### Use it as an integration (automatic after every scrape)

1. Open the scraper you want to export, for example **Google Maps Scraper**, and go to its **Integrations** tab.
2. Choose **Connect Actor or Task** and pick **Google Sheets Export & Sync**.
3. Fill in the sheet URL, your key, the mode and key columns. Open the **JSON** tab of the integration and add `"datasetId": "{{resource.defaultDatasetId}}"`. The Dataset drop-down can't take this text, and without this line the run isn't allowed to read the results.

Every successful run of your scraper now updates your sheet.

### Input example

```json
{
    "spreadsheet": "https://docs.google.com/spreadsheets/d/1AbC.../edit",
    "serviceAccountKey": "{ \"type\": \"service_account\", ... }",
    "sheetName": "Leads",
    "mode": "upsert",
    "keyFields": ["url"],
    "datasetId": "your-dataset-id",
    "columns": ["url", "title", "phone", "address/city"],
    "addSyncedAtColumn": true
}
```

You can also send rows directly in **Rows** (`items`) instead of a dataset, which is handy from the API or from AI agents.

### Output

The Actor writes your data to the sheet, and saves a short summary in its dataset and in the `OUTPUT` record:

```json
{
    "status": "SUCCEEDED",
    "spreadsheetUrl": "https://docs.google.com/spreadsheets/d/1AbC.../edit#gid=0",
    "sheetName": "Leads",
    "mode": "upsert",
    "itemsRead": 250,
    "rowsAdded": 12,
    "rowsUpdated": 30,
    "rowsUnchanged": 208,
    "rowsSkippedDuplicate": 0,
    "rowsSkippedLimit": 0,
    "totalRows": 1042,
    "totalColumns": 9
}
```

### Limits

- **Restarted or resurrected runs:** a run that had already finished writing writes and charges nothing more. One that stopped partway through adding rows writes them again in the same places, so they aren't added twice. If other rows were added to the tab in the meantime, they are left as they are and the log asks you to check for duplicates. To sync new data, start a new run.
- Google Sheets allows up to **10 million cells** per spreadsheet. The Actor checks this before writing and stops with a clear message instead of half-writing your data.
- Text longer than 50,000 characters is shortened to fit in one cell, which is Google's limit.
- Row 1 of the tab is treated as the header row.

### FAQ

**I get "Google Sheets refused access (HTTP 403)".**
Share the sheet with the service account email from your key (`client_email`) as **Editor**, and make sure the Google Sheets API is enabled in that Google Cloud project.

**Why a service account instead of "Sign in with Google"?**
Your key lives in your own Google Cloud project. Your rate limits aren't shared with anyone, and the Actor can only touch sheets you share with that account.

**Will formulas or formatting in my sheet be lost?**
No, in append and upsert mode. Upsert writes only the individual cells whose values changed, and append only writes new rows below your data, so formulas and notes in your own columns are left alone. Replace clears the tab's values (formatting stays).

**Can I export only some columns, in my own order?**
Yes. List them in **Columns to include**. Nested fields use `/`, for example `address/city`.

### Privacy

Your service account key is stored encrypted by Apify and used only for this run. The Actor runs with **limited permissions**: it can read only the dataset you pick or the one from the run that triggered it.

### Support

Found a bug or need a feature? Open an issue on the **Issues** tab, and include the run link.

***

### 🔗 Related Developer Tools & Ecosystem

Extend your automation workflows with our companion tools on the Apify Store:

- 📄 **[YouTube Transcript & Subtitle Extractor](https://apify.com/abzalp/youtube-transcript-extractor)** — Extract clean video transcripts in Markdown & JSON for AI and LLMs.
- 📊 **[Google Sheets Sync & Importer](https://apify.com/abzalp/google-sheets-sync)** — Automatically export and append Apify dataset rows directly to Google Sheets.
- 📑 **[Dataset to Excel Report Generator](https://apify.com/abzalp/dataset-to-excel-report)** — Convert raw scraping datasets into styled, formatted Excel (.xlsx) reports with auto-filters.
- 📸 **[Website Screenshot & PDF Capture API](https://apify.com/abzalp/website-screenshot)** — Capture full-page screenshots and PDFs with mobile/retina presets and ad-blocking.
- 🖼️ **[AI Image Upscaler & Enhancer](https://apify.com/abzalp/ai-image-upscaler)** — Upscale low-resolution photos and images to 4K Ultra HD.
- 🎥 **[Video Compressor & Audio Extractor](https://apify.com/abzalp/video-compressor-converter)** — Fast video compression, format conversion, and clean MP3 audio extraction.

# Changelog

This Actor's version history is a separate document: https://apify.com/abzalp/google-sheets-sync/changelog.md

# Actor input Schema

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

The full URL of your Google Sheet, copied from the browser address bar, or just its ID. Share the sheet with your service account's email as Editor first.

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

Paste the full contents of your Google Cloud service account .json key. It's stored encrypted and used only to write to sheets you share with that service account. See the README for the 3-minute setup.

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

Name of the tab to write to. It's created if it doesn't exist.

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

append: add new rows below existing ones (skips duplicates if you set key columns). upsert: update rows whose key columns match and add the rest. replace: clear the tab and write fresh.

## `keyFields` (type: `array`):

Columns that identify a row, for example \["url"] or \["name", "city"]. Required for upsert. In append mode, rows whose key already exists are skipped, so you never get duplicates.

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

The dataset to export. When you connect this Actor as an integration, use {{resource.defaultDatasetId}} to export the run that triggered it.

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

Optional. A JSON array of objects to write directly, useful from the API or AI agents. Used instead of the dataset when provided.

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

Read at most this many dataset items. 0 means all.

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

Optional. Only these columns, in this order. Nested fields use "/", for example "address/city". Leave empty to include every field.

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

Turn nested objects into separate columns like "address/city". When off, nested values are written as JSON text.

## `addSyncedAtColumn` (type: `boolean`):

Add a column with the time of this sync to each written row.

## Actor input object example

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit",
  "sheetName": "Sheet1",
  "mode": "append",
  "keyFields": [
    "url"
  ],
  "items": [
    {
      "url": "https://example.com",
      "title": "Example"
    }
  ],
  "maxItems": 0,
  "flatten": true,
  "addSyncedAtColumn": false
}
```

# Actor output Schema

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

No description

## `output` (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_SHEET_ID/edit"
};

// Run the Actor and wait for it to finish
const run = await client.actor("abzalp/google-sheets-sync").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_SHEET_ID/edit" }

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,abzalp/google-sheets-sync"
        }
    }
}
```

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/BNX7vorks7WPr2hU4/builds/gIDKEWac5aNIqrrNH/openapi.json
