{
  "openapi": "3.0.1",
  "info": {
    "title": "Google Sheets Sync – Read, Append, Replace (service account)",
    "description": "Read, append or replace Google Sheets data from Apify datasets or JSON using your own Google service account. Retries Google quota errors instead of failing, restores the sheet if a replace fails.",
    "version": "1.0",
    "x-build-id": "XmJ8zFN98Ug4h3gdx"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/petipeti~google-sheets-sync/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-petipeti-google-sheets-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/petipeti~google-sheets-sync/runs": {
      "post": {
        "operationId": "runs-sync-petipeti-google-sheets-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/petipeti~google-sheets-sync/run-sync": {
      "post": {
        "operationId": "run-sync-petipeti-google-sheets-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": {
          "spreadsheet": {
            "title": "Spreadsheet URL or ID",
            "type": "string",
            "description": "Required. Paste the spreadsheet URL (https://docs.google.com/spreadsheets/d/.../edit) or just its ID. Share it with your service account email first."
          },
          "mode": {
            "title": "Mode",
            "enum": [
              "read",
              "append",
              "replace",
              "upsert"
            ],
            "type": "string",
            "description": "read: sheet rows become dataset items (first row = column names). append: adds rows at the bottom and keeps the existing header order. replace: clears the tab and writes new data; the old data is saved to the BACKUP record and restored automatically if writing fails. upsert: finds each row by the key column, writes only the cells that changed, adds new keys at the bottom, writes what changed (e.g. \"price: 1200 → 980\") into the changes column and highlights those rows.",
            "default": "read"
          },
          "rows": {
            "title": "Rows to write as JSON (append / replace / upsert)",
            "type": "array",
            "description": "Paste the data here, NOT in the Key column box. An array of objects, one object per row, e.g. [{\"name\": \"A\", \"price\": 1}]. Used when no dataset ID is given. Ignored in read mode."
          },
          "datasetId": {
            "title": "Or: Apify dataset ID to write (append / replace / upsert)",
            "type": "string",
            "description": "Instead of pasting rows: the items of this dataset are written to the sheet. Typically the default dataset of another Actor run, so you can chain scrapers into Sheets."
          },
          "keyColumn": {
            "title": "Key column (upsert)",
            "type": "string",
            "description": "Just the column name, e.g. name or sku – not JSON. The column that identifies a row; it must exist in the tab's header row (or the tab is empty). Required for upsert mode."
          },
          "changesColumn": {
            "title": "Changes column name (upsert)",
            "type": "string",
            "description": "Just a column name, e.g. changes. Each run writes what changed in that row there (\"price: 1200 → 980\", or \"new\" for added rows). Created at the right if missing. Rows changed by the previous run but not this one are cleared.",
            "default": "changes"
          },
          "highlightChanges": {
            "title": "Highlight changed rows (upsert)",
            "type": "boolean",
            "description": "Changed rows get a light yellow background, new rows light green. The highlight of the previous run is removed from rows that did not change this time. Only the background color is touched.",
            "default": true
          },
          "sheetName": {
            "title": "Tab name",
            "type": "string",
            "description": "Name of the tab (worksheet). Empty = first tab. For append/replace a missing tab is created."
          },
          "serviceAccountKey": {
            "title": "Google service account key (JSON)",
            "type": "string",
            "description": "Required. Paste the whole JSON key file of a Google Cloud service account with the Google Sheets API enabled. Stored encrypted by Apify and used only to call the Google Sheets API for this run. See the README for a 3-minute setup guide."
          },
          "columns": {
            "title": "Column order (optional)",
            "type": "array",
            "description": "Columns to put first, in this order. Other fields follow in the order they appear. In append mode the sheet's existing header order always wins.",
            "items": {
              "type": "string"
            }
          },
          "flattenNested": {
            "title": "Flatten nested objects",
            "type": "boolean",
            "description": "{\"a\": {\"b\": 1}} becomes a column named a.b. Arrays become a.0, a.1, …",
            "default": true
          },
          "valueInputOption": {
            "title": "How Google treats written values",
            "enum": [
              "RAW",
              "USER_ENTERED"
            ],
            "type": "string",
            "description": "RAW keeps \"1,1\" or \"=SUM()\" as text. USER_ENTERED lets Google turn them into numbers, dates and formulas.",
            "default": "RAW"
          },
          "maxItems": {
            "title": "Max items",
            "minimum": 1,
            "maximum": 2000000,
            "type": "integer",
            "description": "Upper limit of rows read or written in one run.",
            "default": 100000
          }
        }
      },
      "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
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}