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

# Create an analytics view

> Persists a named view definition that can later be queried by ID.



## OpenAPI

````yaml /api-reference/openapi.json post /analytics/views
openapi: 3.0.1
info:
  title: Flexprice API
  description: Flexprice API Service
  contact:
    name: API Support
  license:
    name: AGPL-3.0
    url: https://www.gnu.org/licenses/agpl-3.0.html
  version: '1.0'
servers:
  - url: https://us.api.flexprice.io/v1
    description: US Region
  - url: https://api.cloud.flexprice.io/v1
    description: India Region
security: []
paths:
  /analytics/views:
    post:
      tags:
        - Analytics
      summary: Create an analytics view
      description: Persists a named view definition that can later be queried by ID.
      operationId: createAnalyticsView
      requestBody:
        description: View request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateViewRequest'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ViewResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    CreateViewRequest:
      required:
        - definition
        - name
      type: object
      properties:
        definition:
          $ref: '#/components/schemas/analytics.ViewDefinition'
        name:
          type: string
    ViewResponse:
      type: object
      properties:
        definition:
          $ref: '#/components/schemas/analytics.ViewDefinition'
        id:
          type: string
        name:
          type: string
        version:
          type: integer
    errors.ErrorResponse:
      type: object
      properties:
        code:
          $ref: '#/components/schemas/errors.ErrorCode'
        http_status_code:
          type: integer
        message:
          type: string
      x-speakeasy-name-override: ErrorResponse
    analytics.ViewDefinition:
      required:
        - metrics
        - shape
      type: object
      properties:
        dimensions:
          type: array
          items:
            type: string
        filters:
          type: array
          items:
            $ref: '#/components/schemas/analytics.Filter'
        limit:
          type: integer
        metrics:
          minItems: 1
          type: array
          items:
            $ref: '#/components/schemas/types.Metric'
        name:
          type: string
        shape:
          $ref: '#/components/schemas/types.Shape'
        sort:
          type: array
          items:
            $ref: '#/components/schemas/analytics.SortSpec'
        time:
          $ref: '#/components/schemas/analytics.TimeSpecRaw'
        variables:
          type: array
          items:
            $ref: '#/components/schemas/analytics.Variable'
    errors.ErrorCode:
      type: string
      enum:
        - http_client_error
        - system_error
        - internal_error
        - not_found
        - already_exists
        - version_conflict
        - validation_error
        - invalid_operation
        - permission_denied
        - database_error
        - service_unavailable
        - too_many_requests
        - not_implemented
      x-enum-varnames:
        - ErrCodeHTTPClient
        - ErrCodeSystemError
        - ErrCodeInternalError
        - ErrCodeNotFound
        - ErrCodeAlreadyExists
        - ErrCodeVersionConflict
        - ErrCodeValidation
        - ErrCodeInvalidOperation
        - ErrCodePermissionDenied
        - ErrCodeDatabase
        - ErrCodeServiceUnavailable
        - ErrCodeTooManyRequests
        - ErrCodeNotImplemented
      x-speakeasy-name-override: ErrorCode
    analytics.Filter:
      type: object
      properties:
        field:
          type: string
        op:
          $ref: '#/components/schemas/types.FilterOperatorType'
        optional:
          type: boolean
        value:
          type: array
          items:
            type: string
    types.Metric:
      type: string
      enum:
        - usage_quantity
        - event_count
      x-enum-varnames:
        - MetricUsageQuantity
        - MetricEventCount
      x-speakeasy-name-override: Metric
    types.Shape:
      type: string
      enum:
        - timeseries
        - breakdown
      x-enum-varnames:
        - ShapeTimeseries
        - ShapeBreakdown
      x-speakeasy-name-override: Shape
    analytics.SortSpec:
      type: object
      properties:
        dir:
          $ref: '#/components/schemas/types.SortDirection'
        field:
          type: string
    analytics.TimeSpecRaw:
      type: object
      properties:
        grain:
          $ref: '#/components/schemas/types.Grain'
        range:
          type: string
    analytics.Variable:
      required:
        - type
      type: object
      properties:
        default:
          type: array
          items:
            type: string
        name:
          type: string
        required:
          type: boolean
        type:
          $ref: '#/components/schemas/types.VariableType'
    types.FilterOperatorType:
      type: string
      enum:
        - eq
        - contains
        - not_contains
        - gt
        - lt
        - gte
        - in
        - not_in
        - before
        - after
      x-enum-varnames:
        - EQUAL
        - CONTAINS
        - NOT_CONTAINS
        - GREATER_THAN
        - LESS_THAN
        - GREATER_THAN_EQUAL
        - IN
        - NOT_IN
        - BEFORE
        - AFTER
      x-speakeasy-name-override: FilterOperatorType
    types.SortDirection:
      type: string
      enum:
        - asc
        - desc
      x-enum-varnames:
        - SortDirectionAsc
        - SortDirectionDesc
      x-speakeasy-name-override: SortDirection
    types.Grain:
      type: string
      enum:
        - hour
        - day
        - week
        - month
      x-enum-varnames:
        - GrainHour
        - GrainDay
        - GrainWeek
        - GrainMonth
      x-speakeasy-name-override: Grain
    types.VariableType:
      type: string
      enum:
        - date_range
        - string
        - string_list
        - number
        - enum
        - boolean
      x-enum-varnames:
        - VariableTypeDateRange
        - VariableTypeString
        - VariableTypeStringList
        - VariableTypeNumber
        - VariableTypeEnum
        - VariableTypeBoolean
      x-speakeasy-name-override: VariableType
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: Enter your API key in the format *x-api-key &lt;api-key&gt;**
      name: x-api-key
      in: header

````