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

# Asynchronously Ingest Usage Data

> Submit usage data for asynchronous processing. This endpoint accepts a list of customer events and processes them asynchronously as a batch job. The response includes a job ID that can be used to check the status of the batch job.



## OpenAPI

````yaml post /api/v1/usage/ingest-async
openapi: 3.1.0
info:
  title: NinjaAPI
  version: 1.0.0
  description: ''
servers:
  - url: https://api.justpaid.io
security: []
paths:
  /api/v1/usage/ingest-async:
    post:
      summary: Asynchronously Ingest Usage Data
      description: >-
        Submit usage data for asynchronous processing. This endpoint accepts a
        list of customer events and processes them asynchronously as a batch
        job. The response includes a job ID that can be used to check the status
        of the batch job.
      operationId: loopfour_backend_external_api_usage_ingest_usage_data_async
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomerEventList'
            examples:
              example:
                summary: Sample Request
                description: A sample request with multiple customer events.
                value:
                  events:
                    - customer_id: 123e4567-e89b-12d3-a456-426614174000
                      event_name: purchase_made
                      timestamp: '2023-10-01T12:00:00Z'
                      idempotency_key: unique-key-1
                      event_value: 49.99
                      properties:
                        item_id: A100
                        quantity: 2
                    - customer_id: 123e4567-e89b-12d3-a456-426614174001
                      event_name: subscription_started
                      timestamp: '2023-10-02T15:30:00Z'
                      idempotency_key: unique-key-2
                      event_value: 0
                      properties:
                        plan: premium
                        duration: 12_months
        required: true
      responses:
        '200':
          description: Successfully submitted the usage data for asynchronous processing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageDataBatchJobCreateResponseSchema'
              examples:
                successful_submission:
                  summary: Successful Submission
                  value:
                    job_id: a4f8e9be-3d5b-4f8e-8b4d-9b4e5c9f5a2d
                    status: PENDING
                    total_events: 2
                    created_at: '2023-10-10T10:00:00Z'
        '400':
          description: Invalid request due to malformed data.
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
              examples:
                invalid_data:
                  summary: Invalid Data
                  value:
                    detail: Invalid customer_id format.
        '401':
          description: Unauthorized access due to missing or invalid authentication.
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
              examples:
                unauthorized:
                  summary: Unauthorized
                  value:
                    detail: Authentication credentials were not provided.
        '500':
          description: Internal server error occurred while processing the request.
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
              examples:
                server_error:
                  summary: Server Error
                  value:
                    detail: An unexpected error occurred.
      security:
        - HttpBearerAuth: []
components:
  schemas:
    CustomerEventList:
      description: |-
        Represents a list of customer events.

        Attributes:
            events (list[CustomerEvent]): A list of customer events. Each event should be a
                dictionary with at-least the following keys: event_name, timestamp, idempotency_key.
      properties:
        events:
          default: []
          items:
            $ref: '#/components/schemas/CustomerEvent'
          title: Events
          type: array
      title: CustomerEventList
      type: object
    UsageDataBatchJobCreateResponseSchema:
      properties:
        job_id:
          description: The UUID of the created batch job.
          format: uuid
          title: Job Id
          type: string
        status:
          description: The status of the created batch job.
          title: Status
          type: string
        total_events:
          description: The total number of events in the batch job.
          title: Total Events
          type: integer
        created_at:
          description: The timestamp when the batch job was created.
          format: date-time
          title: Created At
          type: string
      required:
        - job_id
        - status
        - total_events
        - created_at
      title: UsageDataBatchJobCreateResponseSchema
      type: object
    CustomerEvent:
      description: |-
        Represents an event associated with a customer in the system.

        Attributes:
            customer_id (Optional[Union[str, uuid.UUID]]): The unique identifier for the customer.
            This can be either a email or a UUID.
            event_name (str): The name of the event being recorded, it should be in snake_case format without spaces.
            for example: 'customer_created'.
            timestamp (str): The timestamp when the event occurred, in ISO 8601 format (e.g. 2024-08-09T00:00:00Z).
            idempotency_key (str): A unique string key to ensure idempotency of event processing.
            This key is used to identify duplicate events.
            item (Optional[uuid.UUID]): An optional billable item UUID that the event can be associated with.
            event_value (Union[float, int]): The value associated with the event. This can be either an integer or a float.
            external_customer_id (Optional[str]): An optional external identifier for the customer, provided as a string.
            properties (Optional[dict]): An optional dictionary containing additional
            properties or metadata associated with the event.
      properties:
        customer_id:
          anyOf:
            - type: string
            - format: uuid
              type: string
            - type: 'null'
          description: >-
            The unique identifier for the customer. This can be either an email
            or a UUID obtained from JustPaid Platform.
          example: 123e4567-e89b-12d3-a456-426614174000
          title: Customer Id
        event_name:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            The name of the event being recorded, this is used to map the event
            in the JustPaid. For example: 'customer_created' or
            'invoice_parsed'.
          example: customer_created
          title: Event Name
        timestamp:
          description: >-
            The timestamp when the event occurred, in ISO 8601 format. the
            tiemstamp should be in UTC timezone.
          example: '2024-08-09T00:00:00Z'
          title: Timestamp
          type: string
        idempotency_key:
          description: >-
            A unique string key to ensure idempotency of event processing. This
            key is used to identify duplicate events. It's recommended to
            generate a new UUID for each event to prevent duplicates.
          example: f47ac10b-58cc-4372-a567-0e02b2c3d479
          title: Idempotency Key
          type: string
        item_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          description: >-
            An optional UUID that the event can be associated with. If provided,
            this should be a UUID obtained from JustPaid Platform using
            `api/v1/usage/events` endpoint. and each item_id is associated with
            a plan_item in the system while creating the customer contract
          example: d3dc2e8f-2c78-4e3c-8b2c-649efdf5dd21
          title: Item Id
        event_value:
          anyOf:
            - type: number
            - type: integer
          description: >-
            The value associated with the event. This can be either an integer
            or a float, this value is used to calculate the billing amount for
            the customer provided that a billing metic is associated with the
            event.
          example: 100
          title: Event Value
        external_customer_id:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            An optional external identifier for the customer, provided as a
            string. this used as an alias to JustPaid customer.
          example: external_12345
          title: External Customer Id
        properties:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          description: >-
            An optional dictionary containing additional properties or metadata
            associated with the event.
          example:
            property1: value1
            property2: 5
          title: Properties
      required:
        - event_name
        - timestamp
        - idempotency_key
      title: CustomerEvent
      type: object
  securitySchemes:
    HttpBearerAuth:
      type: http
      scheme: bearer

````