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

# Create and run a metric collection job

> Creates a metric collection job for the specified calls or chats and metrics, then triggers processing. Provide exactly one of callIds or chatIds.



## OpenAPI

````yaml /api-reference/openapi.documented.json post /v1/metric/collection-jobs
openapi: 3.1.0
info:
  title: Roark Analytics API
  description: >-
    The Roark Analytics API gives you access to the same API that powers the
    award winning Roark Analytics platform.
  version: 1.0.0
servers:
  - description: Production
    url: https://api.roark.ai
security:
  - Bearer: []
tags:
  - name: Agent
  - name: Agent Endpoint
  - name: Call
  - name: Chat
  - name: Metric
  - name: Metric Policy
  - name: Metric Collection Job
  - name: Simulation Persona
  - name: Simulation Scenario
  - name: Simulation Run Plan
  - name: Simulation Run Plan Job
  - name: Simulation Job
  - name: HTTP Request Definition
  - name: Webhook
  - name: Issue
  - name: Knowledge Base
  - name: Call Analysis
  - name: Health
paths:
  /v1/metric/collection-jobs:
    post:
      tags:
        - Metric Collection Job
      summary: Create and run a metric collection job
      description: >-
        Creates a metric collection job for the specified calls or chats and
        metrics, then triggers processing. Provide exactly one of callIds or
        chatIds.
      operationId: postV1MetricCollection-jobs
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMetricCollectionJobInput'
      responses:
        '201':
          description: The created metric collection job
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/MetricCollectionJobResponse'
                required:
                  - data
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Validation error
              example:
                type: validation
                code: invalid_parameter
                message: The request was invalid
                param: email
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Authentication error
              example:
                type: authentication
                code: unauthorized
                message: Authentication required
          description: Unauthorized
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Permission error
              example:
                type: forbidden
                code: permission_denied
                message: You do not have permission to access this resource
          description: Forbidden
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Rate limit error
              example:
                type: rate_limit
                code: too_many_requests
                message: Rate limit exceeded
          description: Too Many Requests
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                description: Server error
              example:
                type: internal
                code: internal_error
                message: Internal server error
          description: Internal Server Error
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Roark from '@roarkanalytics/sdk';


            const client = new Roark({
              bearerToken: process.env['ROARK_API_BEARER_TOKEN'], // This is the default and can be omitted
            });


            const metricCollectionJob = await
            client.metricCollectionJob.create({
              metrics: [{ id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' }],
            });


            console.log(metricCollectionJob.data);
        - lang: Python
          source: |-
            import os
            from roark_analytics import Roark

            client = Roark(
                bearer_token=os.environ.get("ROARK_API_BEARER_TOKEN"),  # This is the default and can be omitted
            )
            metric_collection_job = client.metric_collection_job.create(
                metrics=[{
                    "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
                }],
            )
            print(metric_collection_job.data)
components:
  schemas:
    CreateMetricCollectionJobInput:
      type: object
      properties:
        callIds:
          type: array
          items:
            type: string
            format: uuid
          minItems: 1
          maxItems: 500
          description: >-
            Call IDs to collect metrics for. Mutually exclusive with chatIds.
            Max 500 per request.
        chatIds:
          type: array
          items:
            type: string
            format: uuid
          minItems: 1
          maxItems: 500
          description: >-
            Chat IDs to collect metrics for. Mutually exclusive with callIds.
            Max 500 per request.
        metrics:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                format: uuid
            required:
              - id
          minItems: 1
          maxItems: 20
          description: Metric definitions to collect. Max 20 per request.
      required:
        - metrics
      description: >-
        Input for creating and running a metric collection job. Limits: ≤500
        conversations, ≤20 metrics, ≤5000 total items per request.
    MetricCollectionJobResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier of the metric collection job
        status:
          type: string
          enum:
            - PENDING
            - PROCESSING
            - COMPLETED
            - FAILED
            - CANCELED
          description: Current status of the job
        triggeredBy:
          type: string
          enum:
            - USER_MANUAL
            - USER_API
            - METRIC_POLICY
            - SIMULATION
          description: What triggered this job
        totalItems:
          type: integer
          description: Total number of call-metric pairs to process
        completedItems:
          type: integer
          description: Number of successfully completed items
        failedItems:
          type: integer
          description: Number of failed items
        startedAt:
          type:
            - string
            - 'null'
          description: When the job started processing
        completedAt:
          type:
            - string
            - 'null'
          description: When the job completed
        errorMessage:
          type:
            - string
            - 'null'
          description: Error message if the job failed
        policyIds:
          type: array
          items:
            type: string
            format: uuid
          description: IDs of the metric policies that triggered this job
        createdAt:
          type: string
          description: When the job was created
        updatedAt:
          type: string
          description: When the job was last updated
      required:
        - id
        - status
        - triggeredBy
        - totalItems
        - completedItems
        - failedItems
        - startedAt
        - completedAt
        - errorMessage
        - policyIds
        - createdAt
        - updatedAt
      description: A metric collection job that processes metrics for calls or chats
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          enum:
            - validation
            - authentication
            - forbidden
            - not_found
            - conflict
            - rate_limit
            - internal
          description: The error type category
          examples:
            - validation
            - authentication
        code:
          type: string
          description: Machine-readable error code identifier
          examples:
            - invalid_parameter
            - missing_required_field
            - unauthorized
        message:
          type: string
          description: Human-readable error message
          examples:
            - The request was invalid
            - Authentication required
        param:
          type: string
          description: The parameter that caused the error (if applicable)
          examples:
            - email
            - user_id
        details:
          description: Additional error context information
      required:
        - type
        - code
        - message
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer
      bearerFormat: JWT

````