# Aggregate matching records

## `POST /v1/objects/{object}/aggregate`

Requires the `read` scope.

```json
{
  "tags": [
    "Records"
  ],
  "operationId": "aggregate-records",
  "summary": "Aggregate matching records",
  "description": "Requires the `read` scope.",
  "x-retainer-scope": "read",
  "parameters": [
    {
      "in": "path",
      "name": "object",
      "required": true,
      "description": "Object API name.",
      "example": "company",
      "schema": {
        "type": "string"
      }
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "search": {
              "description": "Keywords within this object only, matched by Postgres full-text search over its label and searchable fields. Every word must match, as a whole word or the start of one (\"Dan\" finds \"Dana\"); accents are ignored.",
              "type": "string",
              "minLength": 1,
              "maxLength": 500
            },
            "filter": {
              "type": "object",
              "propertyNames": {
                "type": "string"
              },
              "additionalProperties": {}
            },
            "aggregates": {
              "default": [],
              "maxItems": 50,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "field": {
                    "type": "string"
                  },
                  "op": {
                    "type": "string",
                    "enum": [
                      "countEmpty",
                      "countNotEmpty",
                      "percentEmpty",
                      "percentNotEmpty",
                      "countUnique",
                      "sum",
                      "avg",
                      "min",
                      "max"
                    ]
                  }
                },
                "required": [
                  "field",
                  "op"
                ],
                "additionalProperties": false
              }
            },
            "groupBy": {
              "description": "A filterable select field: also compute the total and aggregates per option.",
              "type": "string"
            }
          },
          "additionalProperties": false
        },
        "example": {
          "aggregates": [
            {
              "field": "amount",
              "op": "sum"
            }
          ]
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "Successful response.",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/AggregateResult"
          }
        }
      }
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    },
    "default": {
      "$ref": "#/components/responses/ApiError"
    }
  }
}
```

[Full OpenAPI contract](/openapi.json)
