> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useinvent.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Aggregate view records

> Compute count/sum/avg/min/max over the records of a view, optionally grouped, windowed and filtered. Honors the view filter on top of the spec filter.



## OpenAPI

````yaml https://api.useinvent.com/openapi.json post /orgs/{org_id}/views/{view_id}/aggregate
openapi: 3.1.0
info:
  version: 1.0.0
  title: Invent API
servers:
  - url: https://api.useinvent.com
security:
  - bearerAuth: []
paths:
  /orgs/{org_id}/views/{view_id}/aggregate:
    post:
      tags:
        - Orgs Views
      summary: Aggregate view records
      description: >-
        Compute count/sum/avg/min/max over the records of a view, optionally
        grouped, windowed and filtered. Honors the view filter on top of the
        spec filter.
      parameters:
        - schema:
            type: string
          required: true
          description: Org ID
          name: org_id
          in: path
        - schema:
            type: string
          required: true
          description: View ID
          name: view_id
          in: path
      requestBody:
        description: ''
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TableAggregateSpecSchema'
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/TableAggregateSpecSchema'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TableAggregateResultSchema'
components:
  schemas:
    TableAggregateSpecSchema:
      type: object
      properties:
        metric:
          $ref: '#/components/schemas/TableAggregateMetricSchema'
        group_by:
          $ref: '#/components/schemas/TableAggregateGroupBySchema'
        window:
          $ref: '#/components/schemas/TableAggregateWindowSchema'
        filter:
          $ref: '#/components/schemas/FilterSchema'
        compare:
          type: string
          enum:
            - previous_period
        limit:
          type: integer
          minimum: 1
          maximum: 50
      required:
        - metric
    TableAggregateResultSchema:
      oneOf:
        - $ref: '#/components/schemas/TableAggregateValueSchema'
        - $ref: '#/components/schemas/TableAggregateSeriesSchema'
      discriminator:
        propertyName: kind
        mapping:
          value:
            $ref: '#/components/schemas/TableAggregateValueSchema'
          series:
            $ref: '#/components/schemas/TableAggregateSeriesSchema'
    TableAggregateMetricSchema:
      type: object
      properties:
        aggregation:
          $ref: '#/components/schemas/TableAggregationSchema'
        field_key:
          type: string
          minLength: 1
          maxLength: 64
      required:
        - aggregation
    TableAggregateGroupBySchema:
      type: object
      properties:
        field_key:
          type: string
          minLength: 1
          maxLength: 64
        bucket:
          $ref: '#/components/schemas/TableAggregateDateBucketSchema'
      required:
        - field_key
    TableAggregateWindowSchema:
      type: object
      properties:
        field_key:
          type: string
          minLength: 1
          maxLength: 64
        last:
          $ref: '#/components/schemas/TableAggregateWindowLastSchema'
      required:
        - field_key
        - last
    FilterSchema:
      anyOf:
        - $ref: '#/components/schemas/FilterRuleSchema'
        - $ref: '#/components/schemas/FilterGroupSchema'
    TableAggregateValueSchema:
      type: object
      properties:
        kind:
          type: string
          enum:
            - value
        value:
          type:
            - number
            - 'null'
        previous:
          type:
            - number
            - 'null'
      required:
        - kind
        - value
    TableAggregateSeriesSchema:
      type: object
      properties:
        kind:
          type: string
          enum:
            - series
        groups:
          type: array
          items:
            $ref: '#/components/schemas/TableAggregateGroupSchema'
        truncated:
          type: boolean
          description: >-
            True when enum groups overflowed the cap and were folded into
            `__other__`.
      required:
        - kind
        - groups
        - truncated
    TableAggregationSchema:
      type: string
      enum:
        - count
        - sum
        - avg
        - min
        - max
    TableAggregateDateBucketSchema:
      type: string
      enum:
        - day
        - week
        - month
    TableAggregateWindowLastSchema:
      type: string
      enum:
        - 7d
        - 30d
        - 90d
        - 365d
    FilterRuleSchema:
      type: object
      properties:
        type:
          type: string
          enum:
            - rule
        key:
          type: string
          minLength: 1
          maxLength: 64
          pattern: ^[a-z][a-z0-9_]{0,63}$
        operator:
          $ref: '#/components/schemas/FilterOperatorSchema'
        value: {}
      required:
        - type
        - key
        - operator
    FilterGroupSchema:
      type: object
      properties:
        type:
          type: string
          enum:
            - group
        combinator:
          $ref: '#/components/schemas/FilterCombinatorSchema'
        children:
          type: array
          items:
            $ref: '#/components/schemas/FilterSchema'
      required:
        - type
        - combinator
        - children
    TableAggregateGroupSchema:
      type: object
      properties:
        key:
          type:
            - string
            - 'null'
          description: >-
            Group value: enum/string value, bucket start as ISO date,
            `__other__` for the folded tail, null for records without a value.
        value:
          type:
            - number
            - 'null'
      required:
        - key
        - value
    FilterOperatorSchema:
      type: string
      enum:
        - contains
        - not_contains
        - eq
        - neq
        - gt
        - lt
        - gte
        - lte
        - before
        - after
        - on_or_before
        - on_or_after
        - in
        - not_in
        - is_empty
        - is_not_empty
    FilterCombinatorSchema:
      type: string
      enum:
        - and
        - or
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Bearer token authentication using your API key

````