{
  "openapi": "3.0.1",
  "info": {
    "title": "Google Sheets Sync — Apify Dataset Export, Upsert & Import",
    "description": "Sync Apify Datasets to Google Sheets reliably without OAuth crashes. Supports Service Account, 1-click Apps Script & public import, upsert, JSON flattening & 429 retries. $0.005/sync + $0.10/1,000 rows · Failed runs free · AI Agent & MCP ready.",
    "version": "1.0",
    "x-build-id": "vV6uVh8IgyRARRJ1a"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/structmint~google-sheets-dataset-sync/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-structmint-google-sheets-dataset-sync",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/structmint~google-sheets-dataset-sync/runs": {
      "post": {
        "operationId": "runs-sync-structmint-google-sheets-dataset-sync",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/structmint~google-sheets-dataset-sync/run-sync": {
      "post": {
        "operationId": "run-sync-structmint-google-sheets-dataset-sync",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "properties": {
          "operationMode": {
            "title": "Operation Mode",
            "enum": [
              "import_public",
              "export_service_account",
              "import_service_account",
              "export_apps_script"
            ],
            "type": "string",
            "description": "Select import_public for zero-auth public Google Sheet import (ready to click Start immediately), export_service_account or import_service_account for Google Service Account OAuth2, or export_apps_script for zero-GCP-Console webhook export.",
            "default": "import_public"
          },
          "spreadsheetUrlOrId": {
            "title": "Google Sheet URL or Spreadsheet ID",
            "type": "string",
            "description": "Full Google Sheets URL (https://docs.google.com/spreadsheets/d/<ID>/edit) or raw Spreadsheet ID. Required for import_public, import_service_account, and export_service_account. Optional for export_apps_script when your Apps Script targets the bound spreadsheet."
          },
          "sheetName": {
            "title": "Worksheet Tab Name",
            "type": "string",
            "description": "Target tab name (for example 'Class Data', 'Catalog', or 'Apify Data'). In export modes, missing tabs are created automatically. Leave empty to use the first sheet or the gid extracted from the URL.",
            "default": ""
          },
          "gid": {
            "title": "Worksheet GID (Optional)",
            "type": "string",
            "description": "Optional numeric tab GID (for example '0' from #gid=0). Used for import_public when sheetName is empty; automatically extracted from spreadsheetUrlOrId if present.",
            "default": ""
          },
          "writeMode": {
            "title": "Export Write Mode",
            "enum": [
              "append",
              "replace",
              "upsert"
            ],
            "type": "string",
            "description": "Controls how exported rows are written to Google Sheets: append adds rows at the bottom, replace clears the tab and writes fresh rows, and upsert updates existing rows matching primaryKeyColumn in-place and appends new rows without duplicates.",
            "default": "append"
          },
          "dryRun": {
            "title": "Dry Run (Validate & Preview Without Writing)",
            "type": "boolean",
            "description": "When enabled on export modes, reads your Apify Dataset / records, flattens nested JSON, applies deduplication/Watch Mode, and generates OUTPUT.csv without writing to Google Sheets ($0 sync and row charges).",
            "default": false
          },
          "sourceDatasetId": {
            "title": "Source Apify Dataset",
            "type": "string",
            "description": "Apify Dataset to export into Google Sheets. Uses Apify's native Dataset Resource Picker with READ-only scope under LIMITED_PERMISSIONS. In Actor-to-Actor Add integration, map {{resource.defaultDatasetId}} or leave blank to use automatic webhook payload.resource.defaultDatasetId fallback."
          },
          "records": {
            "title": "Inline JSON Records",
            "type": "array",
            "description": "Optional inline JSON array of objects to export directly into Google Sheets (ideal for AI agents, MCP calls, n8n/Make workflows, or quick export tests)."
          },
          "sourceUrl": {
            "title": "Source Data URL (JSON / NDJSON / CSV)",
            "type": "string",
            "description": "Optional public HTTPS URL returning a JSON array, { \"items\": [...] }, NDJSON, or CSV/TSV dataset to export into Google Sheets. Private, loopback, and metadata network ranges are blocked."
          },
          "maxRows": {
            "title": "Maximum Rows per Run",
            "minimum": 1,
            "maximum": 250000,
            "type": "integer",
            "description": "Maximum number of rows to import or export in a single run (1 to 250,000).",
            "default": 50000
          },
          "serviceAccountJson": {
            "title": "Google Service Account JSON",
            "type": "string",
            "description": "Full Google Cloud Service Account JSON key (containing client_email and private_key). Share your Google Sheet with the Service Account email as Editor (export) or Viewer (import). Encrypted at rest by Apify and never logged or written to output."
          },
          "appsScriptUrl": {
            "title": "Google Apps Script Web App URL",
            "type": "string",
            "description": "Deployed Google Apps Script Web App URL (https://script.google.com/macros/s/.../exec) for zero-GCP-Console export_apps_script mode. Strictly restricted to HTTPS script.google.com and script.googleusercontent.com."
          },
          "webhookSecret": {
            "title": "Apps Script Webhook Secret (Optional)",
            "type": "string",
            "description": "Optional shared secret sent in the JSON body (webhookSecret) to your Apps Script Web App to prevent unauthorized writes. Encrypted at rest and never logged."
          },
          "primaryKeyColumn": {
            "title": "Primary Key Column (for Upsert)",
            "type": "string",
            "description": "Column name used to match existing rows when writeMode is 'upsert' (for example 'id', 'sku', 'url', or 'orderId'). Matching rows are updated in-place; unchanged rows are skipped free; new keys are appended.",
            "default": ""
          },
          "deduplicateByColumn": {
            "title": "Deduplicate Rows by Column",
            "type": "string",
            "description": "Optional column name used to remove duplicate rows within this run before pushing to Dataset or writing to Google Sheets.",
            "default": ""
          },
          "flattenNestedObjects": {
            "title": "Flatten Nested JSON Objects",
            "type": "boolean",
            "description": "When enabled (recommended), recursively flattens nested objects into dot-notation columns (for example pricing.amount, specs.weight) so Google Sheets writes never fail on nested JSON.",
            "default": true
          },
          "arrayJoinDelimiter": {
            "title": "Array Join Delimiter",
            "type": "string",
            "description": "Delimiter used when joining primitive arrays (strings/numbers/booleans) into a single cell (for example ', ' or ' | '). Arrays of objects are safely serialized as compact JSON.",
            "default": ", "
          },
          "columns": {
            "title": "Include & Order Specific Columns",
            "type": "array",
            "description": "Optional ordered list of column names to keep. Leave empty to automatically include all discovered columns in stable order.",
            "default": [],
            "items": {
              "type": "string"
            }
          },
          "excludeColumns": {
            "title": "Exclude Columns",
            "type": "array",
            "description": "Optional list of column names to drop before writing to Google Sheets or pushing to the Apify Dataset.",
            "default": [],
            "items": {
              "type": "string"
            }
          },
          "valueInputOption": {
            "title": "Google Sheets Value Input Option",
            "enum": [
              "USER_ENTERED",
              "RAW"
            ],
            "type": "string",
            "description": "Controls whether Google Sheets parses written cell values (numbers, dates, formulas) via USER_ENTERED or stores raw literal strings via RAW.",
            "default": "USER_ENTERED"
          },
          "inferTypes": {
            "title": "Infer Numeric & Boolean Types on Import",
            "type": "boolean",
            "description": "When importing from a public Google Sheet, automatically convert clean numeric and boolean cell values into JSON numbers and booleans while preserving leading-zero strings (such as postal codes or IDs) as strings.",
            "default": true
          },
          "chunkSize": {
            "title": "Rows per API Batch Chunk",
            "minimum": 50,
            "maximum": 5000,
            "type": "integer",
            "description": "Number of rows written per Google Sheets API batch request (50 to 5,000; automatically capped at 1,000 for Apps Script Web App requests).",
            "default": 5000
          },
          "maxRetries": {
            "title": "Max Retries on HTTP 429 / 5xx",
            "minimum": 0,
            "maximum": 8,
            "type": "integer",
            "description": "Number of automatic retry attempts with exponential backoff when Google Sheets returns HTTP 429 rate-limit or 5xx transient errors.",
            "default": 4
          },
          "watchMode": {
            "title": "Enable Incremental Watch Mode",
            "type": "boolean",
            "description": "Persists synced row fingerprints in a user-scoped Named Key-Value Store (structmint-gsheets-watch-v1, 90-day retention) so scheduled runs track previously synced data.",
            "default": false
          },
          "onlyNew": {
            "title": "Skip Unchanged Rows in Watch Mode",
            "type": "boolean",
            "description": "Used with watchMode=true. Skips unchanged rows already synced in prior runs with $0 row charges. Modified rows are still synced.",
            "default": true
          },
          "watchStateKey": {
            "title": "Watch State Namespace Key",
            "type": "string",
            "description": "Stable namespace key separating watch checkpoints for different spreadsheets or recurring schedules.",
            "default": "default-gsheets-watch"
          },
          "maxTotalChargeUsd": {
            "title": "Maximum Total Charge (USD)",
            "minimum": 0.01,
            "maximum": 1000,
            "type": "number",
            "description": "Optional hard spend cap in USD for this run. Also automatically honors Apify's run-level maxTotalChargeUsd."
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_UNBLOCKER_UNITS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}