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

# Get All Batches

> Retrieve a paginated list of all batches for an authenticated user with search capabilities.

## Overview

This endpoint lists every batch created by the authenticated user with pagination and search support. Only non-deleted batches are returned by default. Use this to monitor active campaigns, view batch summaries, and track campaign statistics.

## Prerequisites

* Bearer token for an authenticated user.
* The user must own the batches being retrieved.

## Request

<ParamField header="Authorization" type="string" required>
  Bearer token for the authenticated user.
</ParamField>

<ParamField path="userId" type="string" required>
  User identifier. The authenticated user must match this ID.
</ParamField>

<ParamField query="page" type="integer" default="1">
  Page number for pagination.
</ParamField>

<ParamField query="limit" type="integer" default="10">
  Number of batches to return per page (default: 10).
</ParamField>

<ParamField query="search" type="string">
  Search term to filter batches by `batchName` or `queue_status`.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl --location '{{baseUrl}}/api/call/batches/64e5f12345abcdef12345678?page=1&limit=10&search=Marketing' \
    --header 'Authorization: Bearer {{authToken}}'
  ```
</RequestExample>

## Response

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "message": "Batches fetched successfully",
    "status": true,
    "code": 200,
    "errorMessage": "",
    "data": {
      "batches": [
        {
          "_id": "64e5f12345abcdef98765432",
          "batchName": "Marketing Campaign May 2025",
          "totalCalls": 150,
          "callsPicked": 120,
          "callsCompleted": 100,
          "queue_status": "active",
          "createdAt": "2025-05-01T12:00:00.000Z",
          "updatedAt": "2025-05-15T14:30:00.000Z"
        },
        {
          "_id": "64e5f12345abcdef98765433",
          "batchName": "Sales Outreach June 2025",
          "totalCalls": 200,
          "callsPicked": 150,
          "callsCompleted": 120,
          "queue_status": "paused",
          "createdAt": "2025-06-01T09:00:00.000Z",
          "updatedAt": "2025-06-10T16:45:00.000Z"
        }
      ],
      "pagination": {
        "total": 25,
        "page": 1,
        "limit": 10,
        "totalPages": 3
      }
    }
  }
  ```
</ResponseExample>

<ResponseField name="data" type="object" required>
  Contains the batches array and pagination metadata.
</ResponseField>

<ResponseField name="data.batches" type="array[object]" required>
  Array of batch records with summary statistics.
</ResponseField>

<ResponseField name="data.batches[]._id" type="string" required>
  Unique identifier for the batch.
</ResponseField>

<ResponseField name="data.batches[].batchName" type="string" required>
  Display name for the batch.
</ResponseField>

<ResponseField name="data.batches[].totalCalls" type="integer" required>
  Total number of calls in the batch.
</ResponseField>

<ResponseField name="data.batches[].callsPicked" type="integer" required>
  Number of calls that were picked up/answered.
</ResponseField>

<ResponseField name="data.batches[].callsCompleted" type="integer" required>
  Number of calls that completed successfully.
</ResponseField>

<ResponseField name="data.batches[].queue_status" type="string" required>
  Current status of the batch queue (e.g., "active", "paused", "completed").
</ResponseField>

<ResponseField name="data.batches[].createdAt" type="string" required>
  Timestamp when the batch was created (ISO 8601 format).
</ResponseField>

<ResponseField name="data.batches[].updatedAt" type="string" required>
  Timestamp when the batch was last updated (ISO 8601 format).
</ResponseField>

<ResponseField name="data.pagination" type="object" required>
  Pagination metadata.
</ResponseField>

<ResponseField name="data.pagination.total" type="integer" required>
  Total number of batches matching the search criteria.
</ResponseField>

<ResponseField name="data.pagination.page" type="integer" required>
  Current page number.
</ResponseField>

<ResponseField name="data.pagination.limit" type="integer" required>
  Number of records per page.
</ResponseField>

<ResponseField name="data.pagination.totalPages" type="integer" required>
  Total number of pages available.
</ResponseField>

## Error Handling

* **400 Bad Request** – Invalid `userId` format or invalid query parameters.
* **404 Not Found** – No batches found for the authenticated user.
* **500 Internal Server Error** – Failed to fetch batch data; retry or contact support.

<Note>
  **Filtering Behavior:**

  * Only non-deleted batches are returned (`isDeleted: false`)
  * Use the `search` parameter to filter by batch name or queue status
  * Results are sorted by creation date in descending order (newest first)
  * Pagination helps manage large lists of batches efficiently
</Note>

<Tip>
  Combine this endpoint with `GET /api/call/batch-details/{id}` to first get an overview of all batches, then drill down into specific batch details.
</Tip>


## OpenAPI

````yaml GET /api/call/batches/{userId}
openapi: 3.1.0
info:
  title: Weya AI Public API
  description: >-
    Public API documentation for Weya AI platform - Call Management and DNC (Do
    Not Call) APIs
  version: 1.0.0
servers:
  - url: >-
      https://nexusdev-wjs-api-dev.mangoforest-291de162.swedencentral.azurecontainerapps.io
    description: Development server
security:
  - bearerAuth: []
  - apiKeyAuth: []
paths:
  /api/call/batches/{userId}:
    get:
      tags:
        - Call Management
      summary: Get all batches for user
      description: >-
        Retrieve a paginated list of all batches for an authenticated user with
        search capabilities
      parameters:
        - in: path
          name: userId
          required: true
          schema:
            type: string
        - in: query
          name: page
          schema:
            type: integer
            default: 1
        - in: query
          name: limit
          schema:
            type: integer
            default: 10
        - in: query
          name: search
          schema:
            type: string
      responses:
        '200':
          description: Batches fetched successfully
        '400':
          description: Invalid userId
        '404':
          description: No batches found
        '500':
          description: Internal Server Error
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Bearer token authentication for workspace access
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        API key used for programmatic calling integrations. Find it under
        Settings → API access in your workspace.

````