{
  "openapi": "3.0.1",
  "info": {
    "title": "Google Sheets Integration - Fast Import, Export & Upsert",
    "description": "Seamless bi-directional integration between Google Sheets and Apify. Export datasets to Google Sheets with smart flattening and key-based upserting; or import Google Sheets into Apify datasets with zero-auth public reading.",
    "version": "1.0",
    "x-build-id": "rI5VKmOJ39Z1upWup"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/vnx0~google-sheets-integration/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-vnx0-google-sheets-integration",
        "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/vnx0~google-sheets-integration/runs": {
      "post": {
        "operationId": "runs-sync-vnx0-google-sheets-integration",
        "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/vnx0~google-sheets-integration/run-sync": {
      "post": {
        "operationId": "run-sync-vnx0-google-sheets-integration",
        "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": {
          "mode": {
            "title": "🧭 Operational Mode",
            "enum": [
              "IMPORT_FROM_SHEET",
              "EXPORT_TO_SHEET"
            ],
            "type": "string",
            "description": "Choose whether to import a Google Sheet into an Apify dataset (Read), or export an Apify dataset into Google Sheets (Write / Upsert).",
            "default": "IMPORT_FROM_SHEET"
          },
          "spreadsheet": {
            "title": "🎯 Google Spreadsheet URL or ID",
            "type": "string",
            "description": "Enter the full Google Sheets URL or the unique Spreadsheet ID from the URL (e.g. 1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms).",
            "default": "https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit"
          },
          "sheetName": {
            "title": "📑 Sheet / Tab Name",
            "type": "string",
            "description": "Name of the sheet tab inside the spreadsheet (e.g. 'Sheet1', 'Leads', 'Products'). Automatically created on export if missing.",
            "default": "Class Data"
          },
          "publicSheet": {
            "title": "🔓 Public Sheet Mode (Zero-Auth Streaming)",
            "type": "boolean",
            "description": "Keep enabled when importing from any Google Sheet shared with 'Anyone with the link can view'. Reads the sheet instantly without requiring any Google Service Account credentials.",
            "default": true
          },
          "serviceAccountEmail": {
            "title": "📧 Service Account Client Email (Private Sheets & Export Only)",
            "type": "string",
            "description": "Leave blank if Public Sheet Mode is enabled. Enter your Google Cloud Service Account client email only for private spreadsheets or exports.",
            "default": ""
          },
          "serviceAccountPrivateKey": {
            "title": "🔑 Service Account Private Key (Private Sheets & Export Only)",
            "type": "string",
            "description": "Leave blank if Public Sheet Mode is enabled. Enter your private key (starting with -----BEGIN PRIVATE KEY-----) only for private spreadsheets or exports."
          },
          "serviceAccountJson": {
            "title": "📄 Raw Service Account JSON (Alternative)",
            "type": "string",
            "description": "Leave blank if Public Sheet Mode is enabled. Alternatively paste your entire service-account.json file here."
          },
          "datasetId": {
            "title": "📦 Source Apify Dataset ID",
            "type": "string",
            "description": "The ID of the Apify Dataset to export. If left empty, it will read from the most recent run or sample items.",
            "default": ""
          },
          "writeMode": {
            "title": "⚡ Write Mode",
            "enum": [
              "APPEND",
              "OVERWRITE",
              "UPSERT"
            ],
            "type": "string",
            "description": "APPEND: Adds rows below existing data.\nOVERWRITE: Clears sheet and writes fresh snapshot.\nUPSERT: Matches by primary key to update existing rows and append new ones.",
            "default": "APPEND"
          },
          "upsertKey": {
            "title": "🔑 Primary Key for Upsert",
            "type": "string",
            "description": "Column name used as the unique identifier when Write Mode is set to UPSERT (e.g. 'id', 'url', 'email', 'sku').",
            "default": "id"
          },
          "fields": {
            "title": "📋 Specific Fields to Export (Optional)",
            "type": "array",
            "description": "List of specific property names to export as columns. If empty, all properties in the dataset items will be automatically detected and exported.",
            "default": [],
            "items": {
              "type": "string"
            }
          },
          "flattenNestedObjects": {
            "title": "🧩 Flatten Nested JSON Objects",
            "type": "boolean",
            "description": "If enabled, nested objects are flattened into dot-notated columns (e.g. 'author.name', 'specs.dimensions.width') rather than stringified objects.",
            "default": true
          },
          "flattenDelimiter": {
            "title": "🔣 Nested Key Delimiter",
            "type": "string",
            "description": "Character used to join nested keys (default is period '.'). E.g. '.' produces 'address.city', '_' produces 'address_city'.",
            "default": "."
          },
          "formatSheet": {
            "title": "🎨 Format Header Row (Freeze & Bold)",
            "type": "boolean",
            "description": "Automatically freeze the top header row and apply bold text formatting for clean presentation.",
            "default": true
          },
          "headerRowIndex": {
            "title": "🔢 Header Row Index",
            "minimum": 1,
            "type": "integer",
            "description": "The 1-indexed row number containing column names (default is 1).",
            "default": 1
          },
          "inferTypes": {
            "title": "🧠 Infer Data Types",
            "type": "boolean",
            "description": "Automatically parse numeric strings into numbers, 'TRUE'/'FALSE' into booleans, and ISO strings into date objects.",
            "default": true
          },
          "maxRows": {
            "title": "🛑 Maximum Rows Limit",
            "minimum": 1,
            "type": "integer",
            "description": "Maximum number of rows to import or export in this run. Prevents runaway memory consumption or API quota exhaustion.",
            "default": 10000
          },
          "batchSize": {
            "title": "📦 API Batch Chunk Size",
            "minimum": 1,
            "type": "integer",
            "description": "Number of rows per batched Google Sheets API request. 500 rows per batch delivers optimal throughput while avoiding payload limits.",
            "default": 500
          }
        }
      },
      "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
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}