Read or write a Google Sheet
google_sheets_import_exportRead Google Sheets into rows or write, append, replace, and upsert rows using your own Google credentials, with execution handled on Apify.
Instructions
Read a Google Sheet into rows, or write rows into a Google Sheet. Modes: read (one row per sheet row, keyed by the header row), append, replace (clear the tab, then write), and upsert (update rows whose key_column value already exists, add the rest). Writes need the buyer's own Google credential: a service account key JSON with the sheet shared to its client_email, or an OAuth refresh token with its client, or an OAuth access token. A sheet shared as anyone with the link reads with no credential. Pay per event on Apify: 0.01 USD per block of up to 100 rows written, 0.005 USD per block of up to 100 rows read.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "google_sheets_import_export"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | read (default): the sheet becomes one dataset row per sheet row. append: add rows after the last row. replace: clear the tab, then write the rows. upsert: overwrite the rows whose key_column value is already in the sheet and add the rest. The three write modes need a credential below. | |
| rows | No | Write modes, instead of a dataset. A JSON list of objects, one per sheet row, for example [{"name": "Ann", "email": "ann@example.com"}]. | |
| range | No | Optional, read mode. An A1 range without the tab name, for example A1:F500 or B:D. Default: the whole tab. | |
| sheet | No | Optional. The tab name, or its gid number. Default: the gid in the URL, else the first tab. In a write mode a tab name that does not exist is created. | |
| columns | No | Optional, write modes. Only these keys are written, in this order. Default: every key in the rows, in first seen order. | |
| max_rows | No | Most rows to read or write in this run, 1 to 1,000,000 (default 100,000). | |
| dataset_id | No | Write modes. The Apify dataset whose items go into the sheet, for example the default dataset of another run. In an Apify integration, pass the triggering run's resource.defaultDatasetId variable. Fields starting with # are skipped. | |
| header_row | No | true (default) or false. When true, read rows are keyed by the header row, and writes match your row keys to the header columns and add new columns at the end. When false, read rows are keyed by column letter and writes go column by column in key order. | |
| key_column | No | Upsert mode. The column whose value identifies a row, for example email or url. A row whose value is already in that column is overwritten in place; the rest are added. Rows with no value in it are skipped. | |
| spreadsheet | No | The Google Sheets URL as copied from the browser, or the spreadsheet ID. A #gid= in the URL picks that tab. | |
| value_input | No | raw (default): every value is stored exactly as given, so text starting with = is not run as a formula. user_entered: Google parses values as if typed, so formulas run and dates and numbers are converted. | |
| max_charge_usd | No | Optional. The run stops before a charge that would pass this amount, and never writes a block of rows it could not charge. Summary rows are always returned. | |
| oauth_client_id | No | The client ID that issued the refresh token. | |
| oauth_access_token | No | Instead of the above: a current OAuth access token with the spreadsheets scope. It expires in about an hour, so it suits a single run. | |
| oauth_client_secret | No | The client secret that issued the refresh token. | |
| oauth_refresh_token | No | Instead of a service account: a refresh token from your own Google OAuth client with the spreadsheets scope. Needs oauth_client_id and oauth_client_secret from the same client. | |
| service_account_json | No | Your own service account key file, pasted whole. Share the spreadsheet with its client_email as an Editor (Viewer to read). It is sent only to Google and is never stored, logged, or written to a row. |