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

# Create an event schema

> Create an event schema with attributes and dimensions to process events.



## OpenAPI

````yaml post /event_schema
openapi: 3.0.3
info:
  version: '1.0'
  title: Togai Apis
  contact:
    email: engg@togai.com
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  description: APIs for Togai App
servers:
  - description: Api endpoint
    url: https://api.togai.com/
  - description: Sandbox api endpoint
    url: https://sandbox-api.togai.com/
security:
  - bearerAuth: []
tags:
  - name: Customers
    description: Customer level calls
  - name: Accounts
    description: Account level calls
  - name: Event Schemas
    description: Event Schema level calls
  - name: Usage Meters
    description: Usage Meter level calls
  - name: Price Plans
    description: (DEPRECATED) Price Plan level calls
  - name: PricePlanV2
    description: Price Plan V2 level calls
  - name: Schedules
    description: Account Schedule level calls
  - name: Pricing Rules
    description: Pricing Rules level calls
  - name: Settings
    description: Settings
  - name: Price Experimentation
    description: Price Experimentation apis
  - name: InvoiceGroups
    description: Invoice Group level calls
  - name: Organization
    description: Organization level calls
  - name: FileStorage
    description: File Storage level calls
  - name: Aliases
    description: Alias level calls
  - name: Reports
    description: Report level calls
  - name: ReportTemplates
    description: Report Template level calls
  - name: Customer Portal
    description: Portal level calls
  - name: Alerts
    description: Alert level calls
  - name: Event Management
    description: APIs for getting events ingested in Togai
    externalDocs:
      description: docs
      url: https://togai.com/docs/billing/events
  - name: Metrics
    description: APIs for getting Togai metrics
    externalDocs:
      description: docs
      url: https://togai.com/docs/metrics
  - name: Licenses
    description: APIs for getting or updating license records in Togai
  - name: Entitlements
    description: APIs related to entitlements
  - name: Invoices
    description: Invoices API
  - name: Credits
    description: Credits API
  - name: Wallet
    description: Wallet API
  - name: InvoiceTemplates
    description: InvoiceTemplates API
  - name: InvoiceSequence
    description: InvoiceSequence API
  - name: Payments
    description: Payments API
  - name: Authentication
    description: Authentication API
externalDocs:
  description: Find out more about Togai
  url: https://docs.togai.com/docs
paths:
  /event_schema:
    post:
      tags:
        - Event Schemas
      summary: Create an event schema
      description: Create an event schema with attributes and dimensions to process events.
      operationId: createEventSchema
      requestBody:
        $ref: '#/components/requestBodies/CreateEventSchemaRequest'
      responses:
        '201':
          $ref: '#/components/responses/EventSchemaResponse'
        '400':
          $ref: '#/components/responses/ErrorResponse'
        '401':
          $ref: '#/components/responses/ErrorResponse'
        '403':
          $ref: '#/components/responses/ErrorResponse'
        '404':
          $ref: '#/components/responses/ErrorResponse'
        '429':
          $ref: '#/components/responses/ErrorResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
components:
  requestBodies:
    CreateEventSchemaRequest:
      description: Payload to create event schema
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CreateEventSchemaRequest'
          examples:
            EventSchema:
              $ref: '#/components/examples/CreateEventSchemaRequest'
  responses:
    EventSchemaResponse:
      description: Response for Create and Get event schema requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/EventSchema'
          examples:
            EventSchema:
              $ref: '#/components/examples/EventSchema'
    ErrorResponse:
      description: Error response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            ErrorResponse:
              summary: Error message
              value:
                message: <Reason message>
  schemas:
    CreateEventSchemaRequest:
      description: Request to create event schema
      type: object
      additionalProperties: false
      required:
        - name
        - attributes
        - dimensions
      properties:
        name:
          description: Name of the event. Must be unique for an organization.
          type: string
          maxLength: 50
          pattern: ^[\sa-zA-Z0-9_-]*$
        description:
          description: Description of the event
          type: string
          maxLength: 255
        attributes:
          type: array
          maxItems: 50
          items:
            $ref: '#/components/schemas/EventAttributeSchema'
        dimensions:
          type: array
          maxItems: 50
          items:
            $ref: '#/components/schemas/DimensionsSchema'
        enrichments:
          $ref: '#/components/schemas/Enrichments'
        filterFields:
          type: array
          uniqueItems: true
          items:
            type: string
          description: List of fields that can be used for filtering in usage meter
        eventIdTemplate:
          description: Template used to generate event id based on event payload
          type: string
    EventSchema:
      description: Structure of an event schema
      type: object
      additionalProperties: false
      required:
        - name
        - version
      properties:
        name:
          description: Name of the event. Must be unique for an organization.
          type: string
          maxLength: 50
          pattern: ^[\sa-zA-Z0-9_-]*$
        description:
          description: Description of the event
          type: string
          maxLength: 255
        version:
          description: Version of event schema
          type: integer
          format: int32
          minimum: 1
          example: 1
        status:
          description: |
            Status of event schema
            * DRAFT - Schema is in draft state 
            * ACTIVE - Schema is currently active 
            * INACTIVE - Schema is currently inactive
            * ARCHIVED - Older version of event schema
          type: string
          enum:
            - DRAFT
            - ACTIVE
            - INACTIVE
            - ARCHIVED
          example: DRAFT
        attributes:
          type: array
          maxItems: 50
          items:
            $ref: '#/components/schemas/EventAttributeSchema'
          uniqueItems: true
        dimensions:
          type: array
          maxItems: 50
          items:
            $ref: '#/components/schemas/DimensionsSchema'
          uniqueItems: true
        filterFields:
          type: array
          uniqueItems: true
          items:
            type: string
        featureDetails:
          $ref: '#/components/schemas/FeatureDetails'
        enrichments:
          $ref: '#/components/schemas/Enrichments'
        eventIdTemplate:
          description: Template used to generate event id based on event payload
          type: string
        eventLevelRevenue:
          type: boolean
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    ErrorResponse:
      type: object
      additionalProperties: false
      required:
        - message
      properties:
        message:
          type: string
          description: error description
          maxLength: 500
    EventAttributeSchema:
      description: Structure of an event attribute
      type: object
      additionalProperties: false
      required:
        - name
      properties:
        name:
          description: Name of the event attribute.
          type: string
          maxLength: 50
          pattern: ^[\sa-zA-Z0-9_-]*$
          example: distance
        defaultUnit:
          description: Unit for the attribute
          type: string
          maxLength: 10
          example: kms
    DimensionsSchema:
      description: Structure of dimensions
      type: object
      additionalProperties: false
      required:
        - name
      properties:
        name:
          description: Name of the event dimension
          type: string
          maxLength: 50
          pattern: ^[\sa-zA-Z0-9_-]*$
          example: city
    Enrichments:
      type: object
      additionalProperties: false
      required:
        - fields
      properties:
        dependencies:
          type: array
          items:
            $ref: '#/components/schemas/Dependency'
        fields:
          type: array
          items:
            $ref: '#/components/schemas/Field'
    FeatureDetails:
      description: details of feature associated with event schema with attribute name
      type: object
      additionalProperties: false
      required:
        - featureId
        - attributeName
      properties:
        featureId:
          type: string
        attributeName:
          type: string
    Dependency:
      type: object
      additionalProperties: false
      required:
        - type
        - key
        - name
      properties:
        type:
          type: string
          enum:
            - SETTING
        key:
          type: string
        name:
          type: string
    Field:
      type: object
      additionalProperties: false
      required:
        - name
        - type
        - enrichmentType
        - value
        - order
      properties:
        name:
          type: string
        type:
          type: string
          enum:
            - ATTRIBUTE
            - DIMENSION
        enrichmentType:
          type: string
          enum:
            - VALUE
            - JSON_LOGIC
            - JSON_LOGIC_FROM_DEPENDENCY
        value:
          type: string
        order:
          type: integer
          format: int32
  examples:
    CreateEventSchemaRequest:
      summary: Create event schema request payload
      value:
        name: ride_completed
        description: Cab ride completed
        attributes:
          - name: distance
          - name: time
        dimensions:
          - name: city
          - name: vehicle_type
        enrichments:
          dependencies:
            - type: SETTING
              key: setting.user.meters_per_km
              name: meters_per_km
          fields:
            - name: distanceInKM
              type: ATTRIBUTE
              enrichmentType: JSON_LOGIC
              value: >-
                {"/":[{"var":["attribute.distance"]},{"var":["dependencies.meters_per_km"]}]}
              order: 1
            - name: rideType
              type: DIMENSION
              enrichmentType: JSON_LOGIC
              value: >-
                {"if":[{"<=":[100,{"var":["attribute.distanceInKM"]}]},"long_distance","short_distance"]}
              order: 2
    EventSchema:
      summary: A sample event schema
      value:
        name: ride_completed
        description: Cab ride completed
        version: 1
        attributes:
          - name: distance
          - name: time
        dimensions:
          - name: city
          - name: ride_type
        featureDetails:
          featureId: feature.1122.ahoiud
          attributeName: distance
        eventLevelRevenue: false
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Bearer <credential>

````