# Google Sheets Import – Private Sheets to Dataset, No OAuth (`moriarty_ag/google-sheets-import`) Actor

Read any Google Sheets tab or range – including private sheets – into an Apify dataset. Read-only service account, no browser login, real row numbers, typed values. Works from AI agents (MCP).

- **URL**: https://apify.com/moriarty_ag/google-sheets-import.md
- **Developed by:** [Moriarty Data Tools](https://apify.com/moriarty_ag) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.50 / 1,000 imported 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/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 Import – Private Sheets to Dataset, No OAuth

Read any **Google Sheets** tab or range – **including private sheets** – into an **Apify dataset**,
ready to feed scrapers, AI agents, Make/Zapier/n8n or your own code.

- **Private sheets** – no need to make your sheet public ("Anyone with the link"). Share it with your service account only.
- **No "App blocked by Google"** – your *own* service account. No OAuth screen, no browser login, nothing expires.
- **Read-only** – the Actor asks Google only for read access; sharing as **Viewer** is enough.
- **Works from AI agents (MCP)** – Claude, ChatGPT, Cursor or any MCP client can call it.
- **Any tab, any range** – first tab by default, or a tab by name and a range like `B3:F500`.
- **Clean field names** – empty headers become the column letter, duplicates get `_2`, `_3`.
- **Real row numbers** – each item has `_row`, its row number in the sheet, so you can write results back.
- **Typed values** – numbers stay numbers, booleans stay booleans, dates come as readable text.
- **Big sheets** – read in blocks of 5,000 rows; `maxRows` stops early.
- **Pay only for rows imported** – $0.50 per 1,000 rows; preview rows are free.

Jump to: [Try it](#try-it-first-preview-mode) · [Setup](#quick-start-3-minutes-once) ·
[Example](#example-a-sheet-of-urls-feeds-a-scraper) · [Price](#how-much-does-it-cost) ·
[Input](#input) · [AI agents](#use-it-from-an-ai-agent-mcp) · [FAQ](#faq)

### Try it first: preview mode

Click **Start** with no spreadsheet or key to see sample output in the exact format. With a real
sheet, tick **Preview only** to read just the first 20 rows (not charged).

### Quick start (3 minutes, once)

1. [Google Cloud Console](https://console.cloud.google.com/) → 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 it → **Keys → Add key → Create new key → JSON**. A file downloads.
5. Open your spreadsheet → **Share** → paste the service account email → **Viewer**.
6. In this Actor, paste the JSON file content into **Google service account key** and the sheet URL
   into **Spreadsheet URL or ID**.

Already using [Google Sheets Export](https://apify.com/moriarty_ag/google-sheets-export)? Use the same key.

### Example: a sheet of URLs feeds a scraper

Your team keeps a private sheet, tab **Targets**:

| | A | B | C |
|---|---|---|---|
| 1 | URL | Priority | Notes |
| 2 | https://shop-a.example | high | |
| 3 | https://shop-b.example | low | check weekly |
| 4 | | | |
| 5 | https://shop-c.example | high | |

Input:

```json
{
  "spreadsheet": "https://docs.google.com/spreadsheets/d/1AbC.../edit",
  "serviceAccountJson": "{ \"type\": \"service_account\", ... }",
  "sheetName": "Targets"
}
```

Output (3 rows – the empty row 4 is skipped, row numbers stay real):

```json
[
  { "_row": 2, "URL": "https://shop-a.example", "Priority": "high", "Notes": "" },
  { "_row": 3, "URL": "https://shop-b.example", "Priority": "low", "Notes": "check weekly" },
  { "_row": 5, "URL": "https://shop-c.example", "Priority": "high", "Notes": "" }
]
```

Feed the dataset to any scraper, then send the results back with
[Google Sheets Export](https://apify.com/moriarty_ag/google-sheets-export) – sheet → scraper → sheet.

### How much does it cost?

| What | Price |
|---|---|
| Each row imported | $0.50 per 1,000 rows ($0.0005 per row) |
| Each run start | $0.0005 |
| Platform usage | Included – no compute bill on top |

- A 2,000-row sheet: 2,000 × $0.0005 + $0.0005 ≈ **$1.00**.
- Preview runs (first 20 rows) and failed runs: **no row charges**.
- Set **Maximum cost per run** in the run options: the Actor stops cleanly at that limit.

### Input

| Field | What it does |
|---|---|
| `spreadsheet` | Sheet URL or ID |
| `serviceAccountJson` | Your service account JSON key (secret) |
| `sheetName` | Tab to read (empty = first tab) |
| `range` | Optional block, e.g. `A1:F500` (no tab name) |
| `headerRow` | First row = field names (default on) |
| `valueRender` | Raw values (default), as shown in the sheet, or formulas |
| `skipEmptyRows` | Ignore blank rows (default on) |
| `includeRowNumber` | Add `_row` (default on) |
| `maxRows` | Stop after N rows |
| `dryRun` | Preview the first 20 rows, not charged |

### Output

One dataset item per row, plus an `OUTPUT` record with `rowsImported`, `columns`, `sheetName`
and the spreadsheet link.

### Use it from an AI agent (MCP)

```json
{ "mcpServers": { "apify": { "url": "https://mcp.apify.com?tools=moriarty_ag/google-sheets-import" } } }
```

An agent can read a team's private sheet (a list of products, keywords, leads to check) and work
on it, with no browser login: `{"spreadsheet": "...", "serviceAccountJson": "...", "sheetName": "Keywords"}`.

### FAQ

**How do I import a private Google Sheet into Apify?**
Share the sheet with your service account email as Viewer (setup above). The sheet stays private:
no public link needed.

**How do I read only part of a sheet?**
Put a range in `range`, e.g. `B3:F500`. The first row of the range is the header.

**My table starts below a title. What do I do?**
Use `range` starting at the header row, e.g. `A4:H`.

**Why are some columns called B or C?**
Their header cell is empty. Name them in the sheet, or rename them in your next step.

**How do I get dates and currency exactly as I see them?**
Set **Values** to *As shown in the sheet* (`FORMATTED_VALUE`). The default gives raw numbers
(better for calculations) and dates as text.

**Can I read formulas?**
Yes: **Values** → *Formulas*.

**Is my key safe?**
It's a secret input: stored encrypted, never logged, only sent to Google, and it only works on
sheets you shared with its email. The Actor only requests read access.

### Common errors (and the fix the Actor tells you)

| Message | Fix |
|---|---|
| No access to the spreadsheet | Share the sheet with the service account email as Viewer |
| Google Sheets API is not enabled | Enable it in APIs & Services → Library |
| Tab 'X' does not exist | The message lists the available tabs |
| Not a service-account key | Download a **JSON key** of a service account, not an OAuth client |

Found a bug? Open an issue on the **Issues** tab with the input you used (without your key).

# Actor input Schema

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

Paste the whole Google Sheets address bar, or just the ID. Any ID length works. Leave empty to see sample output.

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

Content of the JSON key of YOUR Google Cloud service account. Share the spreadsheet with its email as Viewer (read-only is enough). Stored encrypted; never logged. See README.

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

Tab to read. Empty = the first tab.

## `range` (type: `string`):

Only this block, e.g. A1:F500 or B3:D (without the tab name). Empty = the whole tab.

## `headerRow` (type: `boolean`):

Use the first row as field names. Empty names become the column letter; duplicates get \_2, \_3.

## `valueRender` (type: `string`):

Raw values (numbers as numbers, dates as text) or exactly as shown in the sheet, or formulas.

## `skipEmptyRows` (type: `boolean`):

Ignore rows with no data. Row numbers in \_row stay the real sheet row numbers.

## `includeRowNumber` (type: `boolean`):

Each item gets \_row with its row number in the sheet. Useful to write results back to the same row.

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

Stop after this many rows. Empty = no limit.

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

Read only the first 20 rows to check the format. Preview rows are not charged.

## Actor input object example

```json
{
  "headerRow": true,
  "valueRender": "UNFORMATTED_VALUE",
  "skipEmptyRows": true,
  "includeRowNumber": true,
  "dryRun": false
}
```

# Actor output Schema

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

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

```

## MCP server setup

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

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/cX62IMkri0Cr16FAf/builds/Ncyk8i7dvRtTMitAU/openapi.json
