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

# List test collections

> Lists the test collections in your organization, newest first. Every other flaky-tests endpoint takes a collection's `id` from here, either as a filter or in a request body.



## OpenAPI

````yaml /openapi-v2.json get /v2/test-collections
openapi: 3.1.0
info:
  title: Trunk API
  version: 2.0.0
  description: >-
    The Trunk public API. Every endpoint is scoped to a single organization and
    requires a credential.


    ## Authentication


    Send **either** an org API key as `Authorization: Bearer <key>`, **or** a
    short-lived first-party token in the `x-trunk-token` header. Existing v1 API
    tokens work unchanged as org API keys.


    The two are not interchangeable for writes. A first-party token obtained by
    **exchanging an org API key** reads merge queues but cannot mutate them — a
    merge-queue mutation forwards the key itself to the merge service, and an
    exchanged token carries no copy of it, so those requests answer `403
    INSUFFICIENT_PERMISSIONS`. A machine caller that mutates merge queues should
    send its org API key directly on `Authorization` for every request. Tokens
    obtained through the CLI device flow are unaffected.


    **Merge-queue authorization is broad today.** The API does not offer an
    enqueue-only capability: organization members and org API keys authorized
    for merge-queue writes can also change configuration (including
    `requiredStatuses`), pause, drain and delete queues. Use such credentials as
    privileged operators, not narrowly scoped CI submission tokens.


    ## Errors


    Every 4xx and 5xx response is a `ErrorResponse`: `{ "error": { "code",
    "message" } }`. Switch on `code`, which is stable; `message` is prose and
    may change at any time.


    **An authorization denial on a read is reported as `404`, not `403`** —
    whether a resource exists must not leak across organizations, so a resource
    in another organization is indistinguishable from one that does not exist.
    `403 INSUFFICIENT_PERMISSIONS` means the credential is valid but is not
    permitted the action (or carries no organization).


    Every response carries an `X-Request-Id` header. Quote it in support
    requests.


    ## Rate limiting


    Requests are limited per organization (currently 100 requests/second).
    Exceeding it returns `429` with `RATE_LIMIT_EXCEEDED`; retry with backoff.
    Note that the limit is enforced at the edge, which does not yet wrap its
    `429` in the `ErrorResponse` envelope described above — treat any `429` as
    rate limiting regardless of body.


    ## Compatibility


    Within v2, Trunk may add: new endpoints, new **optional** response fields,
    new members to any enum (including new `code` values, new queue-entry
    states, and new providers), and new optional request parameters. **Clients
    must tolerate values and fields they do not recognize** rather than failing
    closed — a client that switches exhaustively over an enum will break when a
    member is added. Removals and semantic changes require a new major version.


    ## Provider support


    Merge queues, verification runs and checks are **GitHub-only** today;
    `Check.provider` has a single member for that reason. Impacted-target
    uploads additionally require a `github.com` repository named `owner/repo`.
    The `Provider` enum lists values the repository index can store, not
    surfaces that are fully supported.


    ## Not yet available


    A pull request's **position** in its queue is not exposed, and list
    responses are not ordered by queue position. There are no webhooks —
    monitoring is by polling. `Idempotency-Key` is not yet honored, so a
    mutation that times out must be reconciled by reading the resource back
    rather than blindly retried.
  contact:
    name: Trunk Support
    url: https://docs.trunk.io
servers:
  - url: https://api.trunk.io
    description: Production
security:
  - orgKey: []
  - trunkToken: []
tags:
  - name: mergeQueues
    x-group: Merge Queues
  - name: pullRequests
    x-group: Pull Requests
  - name: mergeQueueVerificationRuns
    x-group: Verification Runs
  - name: impactedTargets
    x-group: Impacted Targets
  - name: repositories
    x-group: Repositories
  - name: dynamicCi
    x-group: Dynamic CI
  - name: testCollections
    x-group: Test Collections
  - name: testCases
    x-group: Test Cases
paths:
  /v2/test-collections:
    get:
      tags:
        - testCollections
      summary: List test collections
      description: >-
        Lists the test collections in your organization, newest first. Every
        other flaky-tests endpoint takes a collection's `id` from here, either
        as a filter or in a request body.
      operationId: testCollections.list
      parameters:
        - schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
            description: Page size, between 1 and 100.
            example: 25
          required: false
          description: Page size, between 1 and 100.
          name: limit
          in: query
        - schema:
            type: string
            description: >-
              Opaque cursor from a previous response's `nextCursor`. A cursor is
              bound to the operation and filter it was minted for.
            example: AQEKZm9vYmFy
          required: false
          description: >-
            Opaque cursor from a previous response's `nextCursor`. A cursor is
            bound to the operation and filter it was minted for.
          name: cursor
          in: query
        - schema:
            type: boolean
            default: false
            description: >-
              Set true to include `total` in the response. Costs an extra COUNT
              query, so it is off by default.
            example: false
          required: false
          description: >-
            Set true to include `total` in the response. Costs an extra COUNT
            query, so it is off by default.
          name: includeTotal
          in: query
        - schema:
            type: string
            minLength: 1
            description: Case-insensitive substring match on the name.
            example: backend
          required: false
          description: Case-insensitive substring match on the name.
          name: q
          in: query
      responses:
        '200':
          description: A page of test collections
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestCollectionList'
        '400':
          description: '`VALIDATION_FAILED` | `INVALID_CURSOR`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: '`AUTHENTICATION_REQUIRED` | `INVALID_TOKEN`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: '`RATE_LIMIT_EXCEEDED`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: '`INTERNAL_ERROR`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    TestCollectionList:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/TestCollection'
          maxItems: 100
        nextCursor:
          type:
            - string
            - 'null'
          description: >-
            Opaque cursor for the next page, or null on the last page. Pass it
            back verbatim as `cursor`; do not construct or inspect one.
          example: AQEKZm9vYmFy
        hasMore:
          type: boolean
          description: True when another page is available.
          example: true
        total:
          type: integer
          description: >-
            Total rows matching the filter. Present only when the request set
            `includeTotal=true`.
          example: 1247
      required:
        - data
        - nextCursor
        - hasMore
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              $ref: '#/components/schemas/ErrorCode'
            message:
              type: string
              description: >-
                Human-readable description of what went wrong. Not stable — do
                not parse.
              example: No merge queue found with ID xK9mP2nQ
          required:
            - code
            - message
      required:
        - error
      description: >-
        The uniform error envelope. Every 4xx and 5xx response in this API has
        this shape.
    TestCollection:
      type: object
      properties:
        id:
          type: string
          description: The collection's id.
          example: aB3xY9kQ
        name:
          type: string
          example: Backend integration tests
        description:
          type:
            - string
            - 'null'
          example: Owned by the platform team.
        testCaseCount:
          type: integer
          description: >-
            Distinct test cases seen in this collection. Reflects ingested
            uploads, so a brand-new collection reports 0 until its first upload
            is processed.
          example: 1284
        quarantineEnabled:
          type: boolean
          description: >-
            Whether quarantining is turned on for this collection. False until
            configured.
          example: true
        autoQuarantineEnabled:
          type: boolean
          description: >-
            Whether flaky tests are quarantined automatically. False until
            configured.
          example: false
        createdAt:
          type: string
          format: date-time
          example: '2026-01-14T09:12:00.000Z'
        updatedAt:
          type: string
          format: date-time
          example: '2026-07-20T16:44:10.000Z'
      required:
        - id
        - name
        - description
        - testCaseCount
        - quarantineEnabled
        - autoQuarantineEnabled
        - createdAt
        - updatedAt
    ErrorCode:
      type: string
      enum:
        - AUTHENTICATION_REQUIRED
        - INVALID_TOKEN
        - INSUFFICIENT_PERMISSIONS
        - INTERNAL_ERROR
        - VALIDATION_FAILED
        - NOT_FOUND
        - INVALID_CURSOR
        - MERGE_QUEUE_NOT_FOUND
        - PR_ALREADY_ENQUEUED
        - PR_NOT_ENQUEUEABLE
        - UPSTREAM_ERROR
        - VERIFICATION_RUN_NOT_FOUND
        - PR_NOT_FOUND
        - REPOSITORY_NOT_FOUND
        - IMPACTED_TARGETS_UNSUPPORTED
        - QUEUE_ALREADY_EXISTS
        - QUEUE_HAS_ACTIVE_ENTRIES
        - MODE_CHANGE_IN_PROGRESS
        - PR_NOT_IN_ACTIVE_STATE
        - MERGE_QUEUE_NOT_CREATABLE
        - PR_TESTS_NOT_RESTARTABLE
        - PROVIDER_URL_NOT_FOUND
        - CI_HOST_UNSUPPORTED
        - CI_SCOPE_NOT_FOUND
        - TEST_COLLECTION_NOT_FOUND
        - TEST_CASE_NOT_FOUND
        - RATE_LIMIT_EXCEEDED
      description: >-
        Stable machine-readable error identifier. Switch on this, never on
        `message`. A shipped code's meaning never changes, but **new codes may
        be added within v2** — treat an unrecognized code as a generic failure
        of its HTTP status rather than failing closed.
      example: MERGE_QUEUE_NOT_FOUND
  securitySchemes:
    orgKey:
      type: http
      scheme: bearer
      description: >-
        An org-scoped API key, sent as `Authorization: Bearer <key>`. Existing
        v1 tokens work here unchanged. There is no enqueue-only or read/write
        scope: an org key authorized for merge-queue writes can invoke every
        merge-queue mutation, including changing merge-protection configuration
        and pausing, draining or deleting a queue.
    trunkToken:
      type: apiKey
      in: header
      name: x-trunk-token
      description: >-
        A short-lived first-party token, sent in the `x-trunk-token` header.
        Obtain one through the CLI device-authentication flow, or by exchanging
        an org API key (`POST /v2/auth/api-key/login`).


        **A token exchanged from an org API key reads merge queues but cannot
        mutate them.** A merge-queue mutation forwards the org API key itself to
        the merge service, and an exchanged token carries no copy of it, so
        those requests answer `403 INSUFFICIENT_PERMISSIONS`. A machine caller
        that mutates merge queues should send the org API key directly as
        `Authorization: Bearer <key>` rather than exchanging it. Tokens from the
        device flow are unaffected.

````