{
  "openapi": "3.0.1",
  "info": {
    "title": "Group By & Aggregate: Pivot Table for Datasets",
    "description": "Groups the rows of an Apify dataset or CSV/JSON files by one or more columns and computes count, sum, average, min, max, distinct count, first, last or median per group, with an optional pivot. Empty input runs a free demo.",
    "version": "0.1",
    "x-build-id": "CfPyAQPUsz95VLKK7"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/ucchiii~dataset-groupby-aggregate/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-ucchiii-dataset-groupby-aggregate",
        "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/ucchiii~dataset-groupby-aggregate/runs": {
      "post": {
        "operationId": "runs-sync-ucchiii-dataset-groupby-aggregate",
        "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/ucchiii~dataset-groupby-aggregate/run-sync": {
      "post": {
        "operationId": "run-sync-ucchiii-dataset-groupby-aggregate",
        "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": {
          "datasetId": {
            "title": "Apify dataset",
            "type": "string",
            "description": "Dataset ID (a finished run's 'defaultDatasetId') or a dataset URL from Apify Console whose rows you want to group. You can combine it with file URLs: the dataset rows are read first. Leave this and the file URLs empty for a free demo."
          },
          "fileUrls": {
            "title": "File URLs",
            "type": "array",
            "description": "Public http(s) links to CSV, TSV, JSON or NDJSON files, up to 20 of them and 100 MB each (JSON arrays up to 50 MB). All files are read as one table, so they should have the same columns. Links to internal networks are blocked.",
            "items": {
              "type": "string"
            }
          },
          "groupBy": {
            "title": "Group by columns",
            "type": "array",
            "description": "Column(s) whose values define a group, such as 'country' or 'category' (up to 10). Rows with the same values in all of them form one group. Nested fields work with dots (address.city). Leave empty to get one row with the totals of the whole table.",
            "items": {
              "type": "string"
            }
          },
          "aggregations": {
            "title": "Aggregations",
            "type": "array",
            "description": "List of calculations, each an object with 'name' (the output column), 'field' (the input column) and 'function': count, sum, avg, min, max, count_distinct, first, last or median. 'count' without 'field' counts rows; with a field it counts rows where that field is not empty. Empty = one 'count' column."
          },
          "trimValues": {
            "title": "Trim spaces in values",
            "type": "boolean",
            "description": "Ignore spaces, tabs and line breaks (also full-width spaces) at the start and end of group-by values, so ' North ' and 'North' fall into one group. The output shows the first value seen, trimmed. Default: on.",
            "default": true
          },
          "ignoreCase": {
            "title": "Ignore upper/lower case in group values",
            "type": "boolean",
            "description": "Put 'north', 'North' and 'NORTH' into one group (also used by count_distinct). Numbers always match their text form (123, 123.0 and '123' are the same group); leading zeros are kept. Default: off.",
            "default": false
          },
          "pivotColumn": {
            "title": "Pivot column (optional)",
            "type": "string",
            "description": "Simple pivot table: the values of this column become output columns (for example quarter: Q1, Q2, Q3, Q4), each holding one aggregation per group. Leave empty for no pivot. At most 'Pivot: max columns' different values."
          },
          "pivotField": {
            "title": "Pivot: value column",
            "type": "string",
            "description": "The column the pivot cells are calculated from, such as 'amount'. Needed for every pivot function except 'count', which counts rows. Used only when a pivot column is set."
          },
          "pivotFunction": {
            "title": "Pivot: function",
            "enum": [
              "sum",
              "count",
              "avg",
              "min",
              "max",
              "count_distinct",
              "first",
              "last",
              "median"
            ],
            "type": "string",
            "description": "How the values of one group and one pivot value are combined into the cell. Used only when a pivot column is set. Default: sum.",
            "default": "sum"
          },
          "pivotFillZero": {
            "title": "Pivot: show 0 for empty cells",
            "type": "boolean",
            "description": "A group that has no row for a pivot value gets null in that column. Turn this on to write 0 instead, which is handy for sums and counts. Default: off.",
            "default": false
          },
          "pivotMaxColumns": {
            "title": "Pivot: max columns",
            "minimum": 1,
            "maximum": 1000,
            "type": "integer",
            "description": "Safety limit for the number of different pivot values. If the pivot column has more, the run stops before anything is written or charged, so you do not get thousands of columns by mistake. Default: 100.",
            "default": 100
          },
          "sortBy": {
            "title": "Sort by (output column)",
            "type": "string",
            "description": "Name of an output column to sort the groups by: a group-by column, an aggregation name or a pivot column. Numbers sort as numbers; empty values go last. Leave empty to keep the order in which groups first appear."
          },
          "sortOrder": {
            "title": "Sort order",
            "enum": [
              "asc",
              "desc"
            ],
            "type": "string",
            "description": "Direction of the sort. Use descending with 'Limit' to get a top list. Used only when 'Sort by' is set. Default: ascending.",
            "default": "asc"
          },
          "limit": {
            "title": "Limit (keep the first N groups)",
            "minimum": 1,
            "type": "integer",
            "description": "Keep only the first N groups after sorting, for example 10 for a top 10. All input rows are still read and charged. Leave empty to keep every group."
          },
          "roundDecimals": {
            "title": "Round decimals",
            "minimum": 0,
            "maximum": 15,
            "type": "integer",
            "description": "Round sums, averages and medians to this many decimals. Leave empty to keep up to 10 decimals (this only hides floating-point noise such as 0.30000000000000004)."
          },
          "maxInputRows": {
            "title": "Max input rows",
            "minimum": 1,
            "maximum": 10000000,
            "type": "integer",
            "description": "Stop reading after this many input rows. This caps run time and cost ($0.70 per 1,000 rows); the result then covers only the rows read, and rows beyond the limit are not charged. Maximum 10,000,000. Default: 1,000,000.",
            "default": 1000000
          }
        }
      },
      "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
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}