# Dataset → Google Sheets Incremental Sync (`starshaped_bullsnake/dataset-google-sheets-incremental-sync`) Actor

Sync Apify Dataset rows to Google Sheets and automatically remember the last synced Dataset offset. Also supports append, replace, and upsert.

- **URL**: https://apify.com/starshaped\_bullsnake/dataset-google-sheets-incremental-sync.md
- **Developed by:** [Starshape Tools](https://apify.com/starshaped_bullsnake) (community)
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.00005 / actor start

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Dataset → Google Sheets Incremental Sync

Sync an Apify Dataset to Google Sheets **without manually tracking offsets**.

The recommended mode remembers the last successfully synced Dataset offset in a persistent Apify Key-Value Store. Schedule the Actor every hour, every day, or after your scraper finishes, and only new Dataset items are appended.

### What problem does it solve?

Typical workflow:

```text
Scraper → Apify Dataset → Google Sheets
```

A normal append workflow can duplicate old rows on every scheduled run. This Actor keeps a checkpoint and only reads items after the previous successful sync.

```text
Run 1: Dataset items 0–999   → Sheets → checkpoint = 1000
Run 2: Dataset items 1000–1049 → Sheets → checkpoint = 1050
Run 3: no new items          → no write
```

The checkpoint moves **only after the Google Sheets write succeeds**.

### Features

- Incremental Dataset → Google Sheets sync
- Automatic persistent offset checkpoint
- No manual offset management
- Append, replace, and upsert one-shot modes
- Google Service Account authentication
- Retry with exponential backoff for Google 429/5xx
- RAW writes to avoid interpreting incoming strings as formulas
- Dry-run validation
- Configurable batch and row limits
- Machine-readable run summary

### Recommended setup

#### 1. Create a Google Service Account

In Google Cloud:

1. Create/select a project.
2. Enable **Google Sheets API**.
3. Create a **Service Account**.
4. Create a JSON key.
5. Copy the Service Account `client_email`.

#### 2. Share the spreadsheet

Share the target Google Sheet with the Service Account `client_email` as **Editor**.

#### 3. Run incremental sync

Set:

- `operation`: `incremental_append`
- `sourceDatasetId`: your Apify Dataset
- `spreadsheet`: target Sheet URL or ID
- `sheetName`: target tab
- `serviceAccountJson`: Service Account JSON

The first successful run starts at offset 0. Later runs continue from the stored offset automatically.

### Resetting the checkpoint

Set `resetCheckpoint` to `true` for one run.

This restarts incremental sync from Dataset offset 0.

> Warning: restarting from zero can intentionally append duplicates if your sheet already contains those rows.

### Checkpoint identity

By default, the Actor derives a checkpoint from:

```text
sourceDatasetId + spreadsheetId + sheetName
```

Use `syncKey` if you need an explicit stable checkpoint identifier.

### Other modes

#### Append

Adds all incoming rows.

#### Replace

Clears values from the target tab and writes the incoming table again.

#### Upsert

Merges rows by `keyColumn`.

For complex spreadsheets with formulas inside the data grid, use Incremental append instead of Replace/Upsert.

### Input source

Incremental append requires an Apify Dataset.

Append, Replace, and Upsert can use either:

- `sourceDatasetId`, or
- inline `rows`.

### Privacy

The Google Service Account credential is a **secret Actor input**. Do not put credentials into the README, issues, logs, or sample outputs.

### Limitations

- The target spreadsheet and tab must already exist.
- Do not run two incremental syncs for the exact same checkpoint concurrently; concurrent runs can append duplicate rows.
- Upsert rewrites the tab's data grid and is intended for plain data tables.
- Google Sheets API quotas still apply.
- This Actor does not create or manage Google Cloud credentials for you.

### Suggested automation

Create an Apify Task with your saved input, then add a schedule.

```text
Scraper runs
     ↓
Dataset grows
     ↓
Scheduled Incremental Sync
     ↓
Only new rows reach Google Sheets
```

### Output

Each run writes a summary with:

- source offset
- next offset
- source row count
- rows written
- target sheet
- duration
- status

Statuses include:

- `SYNC_COMPLETE`
- `NO_NEW_ROWS`
- `DRY_RUN_OK`

# Actor input Schema

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

Google Sheets spreadsheet ID or full spreadsheet URL.

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

Existing tab name inside the spreadsheet, for example Sheet1.

## `operation` (type: `string`):

Incremental append remembers the last Dataset offset and syncs only new items. Other modes behave as one-shot operations.

## `sourceDatasetId` (type: `string`):

Dataset to sync. Required for Incremental append. For other modes, you can instead use Inline rows.

## `rows` (type: `array`):

Optional JSON object array for append, replace, or upsert. Incremental append requires a Dataset.

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

Optional explicit column order. If empty, columns are inferred from incoming row keys.

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

Required only for upsert. Rows with the same non-empty key are updated instead of appended.

## `serviceAccountJson` (type: `object`):

Complete Google Service Account credential JSON. Share the target Sheet with its client\_email before running.

## `checkpointStoreName` (type: `string`):

Named Apify Key-Value Store used to persist incremental offsets across Actor runs.

## `syncKey` (type: `string`):

Optional stable identifier for the incremental checkpoint. Leave empty to derive one from Dataset + spreadsheet + sheet.

## `resetCheckpoint` (type: `boolean`):

If true, Incremental append starts again from Dataset offset 0. The checkpoint is updated only after a successful Sheet write.

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

Safety limit for source rows processed in one run. Incremental mode continues from the next offset on the following run.

## `batchSize` (type: `integer`):

Rows written per Google Sheets API update request.

## `dryRun` (type: `boolean`):

Validate access and show the planned sync without modifying Google Sheets or advancing the checkpoint.

## Actor input object example

```json
{
  "sheetName": "Sheet1",
  "operation": "incremental_append",
  "checkpointStoreName": "google-sheets-sync-checkpoints",
  "resetCheckpoint": false,
  "maxRows": 50000,
  "batchSize": 5000,
  "dryRun": false
}
```

# Actor output Schema

## `dataset` (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("starshaped_bullsnake/dataset-google-sheets-incremental-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 = {}

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,starshaped_bullsnake/dataset-google-sheets-incremental-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/uvZzLFnTKWefRg8ix/builds/KaHStINh5Ykpz1cLJ/openapi.json
