openapi: 3.0.2
info:
  title: Insights API
  description: API powering the Insights feature of Algolia.
  version: 0.0.1
components:
  securitySchemes:
    appId:
      type: apiKey
      in: header
      name: X-Algolia-Application-Id
    apiKey:
      type: apiKey
      in: header
      name: X-Algolia-API-Key
  parameters:
    PathInPath:
      name: path
      in: path
      description: >-
        The path of the API endpoint to target, anything after the /1 needs to
        be specified.
      required: true
      schema:
        type: string
        example: /keys
    Parameters:
      name: parameters
      in: query
      description: Query parameters to be applied to the current query.
      schema:
        type: object
        additionalProperties: true
  schemas:
    ErrorBase:
      description: Error.
      type: object
      additionalProperties: true
      properties:
        message:
          type: string
          example: Invalid Application-Id or API-Key
    eventType:
      type: string
      enum:
        - click
        - conversion
        - view
  responses:
    BadRequest:
      description: Bad request or request arguments.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    FeatureNotEnabled:
      description: This feature is not enabled on your Algolia account.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    MethodNotAllowed:
      description: Method not allowed with this API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    IndexNotFound:
      description: Index not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    UnprocessableEntity:
      description: Unprocessable Entity.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
    RequestEntityTooLarge:
      description: Request Entity Too Large.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorBase'
servers:
  - url: https://insights.{region}.algolia.io
    variables:
      region:
        enum:
          - us
          - de
        default: us
  - url: https://insights.algolia.io
security:
  - appId: []
    apiKey: []
tags:
  - name: events
    x-displayName: Events
    description: Events operations.
x-tagGroups:
  - name: General
    tags:
      - events
paths:
  /1{path}:
    get:
      operationId: get
      summary: Send requests to the Algolia REST API
      description: This method allow you to send requests to the Algolia REST API.
      parameters:
        - $ref: '#/components/parameters/PathInPath'
        - $ref: '#/components/parameters/Parameters'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
        '400':
          $ref: '#/components/responses/BadRequest'
        '402':
          $ref: '#/components/responses/FeatureNotEnabled'
        '403':
          $ref: '#/components/responses/MethodNotAllowed'
        '404':
          $ref: '#/components/responses/IndexNotFound'
    post:
      operationId: post
      requestBody:
        description: The parameters to send with the custom request.
        content:
          application/json:
            schema:
              type: object
      summary: Send requests to the Algolia REST API
      description: This method allow you to send requests to the Algolia REST API.
      parameters:
        - $ref: '#/components/parameters/PathInPath'
        - $ref: '#/components/parameters/Parameters'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
        '400':
          $ref: '#/components/responses/BadRequest'
        '402':
          $ref: '#/components/responses/FeatureNotEnabled'
        '403':
          $ref: '#/components/responses/MethodNotAllowed'
        '404':
          $ref: '#/components/responses/IndexNotFound'
    put:
      operationId: put
      requestBody:
        description: The parameters to send with the custom request.
        content:
          application/json:
            schema:
              type: object
      summary: Send requests to the Algolia REST API
      description: This method allow you to send requests to the Algolia REST API.
      parameters:
        - $ref: '#/components/parameters/PathInPath'
        - $ref: '#/components/parameters/Parameters'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
        '400':
          $ref: '#/components/responses/BadRequest'
        '402':
          $ref: '#/components/responses/FeatureNotEnabled'
        '403':
          $ref: '#/components/responses/MethodNotAllowed'
        '404':
          $ref: '#/components/responses/IndexNotFound'
    delete:
      operationId: del
      summary: Send requests to the Algolia REST API
      description: This method allow you to send requests to the Algolia REST API.
      parameters:
        - $ref: '#/components/parameters/PathInPath'
        - $ref: '#/components/parameters/Parameters'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
        '400':
          $ref: '#/components/responses/BadRequest'
        '402':
          $ref: '#/components/responses/FeatureNotEnabled'
        '403':
          $ref: '#/components/responses/MethodNotAllowed'
        '404':
          $ref: '#/components/responses/IndexNotFound'
  /1/events:
    post:
      tags:
        - events
      operationId: pushEvents
      summary: Push events
      description: |
        This command pushes an array of events.

        An event is
          - an action: `eventName`
          - performed in a context: `eventType`
          - at some point in time provided: `timestamp`
          - by an end user: `userToken`
          - on something: `index`


        Notes:
          - To be accepted, all events sent must be valid.
          - The size of the body must be *less than 2 MB*.
          - When an event is tied to an Algolia search, it must also provide a `queryID`. If that event is a `click`, their absolute `positions` should also be passed.
          - We consider that an `index` provides access to 2 resources: objects and filters. An event can only interact with a single resource type, but not necessarily on a single item. As such an event will accept an array of `objectIDs` or `filters`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              title: InsightEvents
              type: object
              description: Object containing the events sent.
              additionalProperties: false
              required:
                - events
              properties:
                events:
                  type: array
                  description: Array of events sent.
                  items:
                    title: InsightEvent
                    type: object
                    description: Insights event.
                    additionalProperties: false
                    maximum: 1000
                    properties:
                      eventType:
                        $ref: '#/components/schemas/eventType'
                      eventName:
                        type: string
                        maximum: 64
                        description: A user-defined string used to categorize events.
                      index:
                        type: string
                        description: Name of the targeted index.
                      userToken:
                        type: string
                        pattern: '[a-zA-Z0-9_-=/+]{1,128}'
                        description: >-
                          A user identifier. Depending if the user is logged-in
                          or not, several strategies can be used from a
                          sessionId to a technical identifier. You should always
                          send pseudonymous or anonymous userTokens.
                      timestamp:
                        type: integer
                        format: int64
                        description: >-
                          Time of the event expressed in milliseconds since the
                          Unix epoch.
                      queryID:
                        type: string
                        description: >-
                          Algolia queryID. This is required when an event is
                          tied to a search.
                      objectIDs:
                        type: array
                        description: >-
                          An array of index objectID. Limited to 20 objects. An
                          event can’t have both objectIDs and filters at the
                          same time.
                        items:
                          type: string
                      filters:
                        type: array
                        description: >-
                          An array of filters. Limited to 10 filters. An event
                          can’t have both objectIDs and filters at the same
                          time.
                        items:
                          type: string
                      positions:
                        type: array
                        description: >-
                          Position of the click in the list of Algolia search
                          results. This field is required if a queryID is
                          provided. One position must be provided for each
                          objectID.
                        items:
                          type: integer
                    required:
                      - eventType
                      - eventName
                      - index
                      - userToken
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                title: pushEventsResponse
                type: object
                additionalProperties: false
                required:
                  - message
                properties:
                  message:
                    type: string
                    description: A message confirming the event push.
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '413':
          $ref: '#/components/responses/UnprocessableEntity'
        '422':
          $ref: '#/components/responses/RequestEntityTooLarge'
