> ## 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.

# Get a test case

> Returns one test case by its globally unique id, with the labels, quarantine override and active monitors currently applied to it. Ids come from list responses; they are opaque and not derivable client-side.

A test case in another organization is reported as `404`, not `403`, and so is a malformed id — a caller must not be able to probe which ids exist.



## OpenAPI

````yaml /openapi-v2.json get /v2/test-cases/{testCaseId}
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-cases/{testCaseId}:
    get:
      tags:
        - testCases
      summary: Get a test case
      description: >-
        Returns one test case by its globally unique id, with the labels,
        quarantine override and active monitors currently applied to it. Ids
        come from list responses; they are opaque and not derivable client-side.


        A test case in another organization is reported as `404`, not `403`, and
        so is a malformed id — a caller must not be able to probe which ids
        exist.
      operationId: testCases.get
      parameters:
        - schema:
            type: string
            minLength: 1
            description: The test case's globally unique id.
            example: bfeebcf4-0000-8000-8000-000000000001
          required: true
          description: The test case's globally unique id.
          name: testCaseId
          in: path
        - schema:
            type: string
            enum:
              - metrics
            description: Set to `metrics` to embed this test's metrics for `period`.
            example: metrics
          required: false
          description: Set to `metrics` to embed this test's metrics for `period`.
          name: include
          in: query
        - schema:
            type: string
            enum:
              - 1d
              - 7d
              - 14d
              - 30d
            description: Metrics window. Required with `include=metrics`.
            example: 7d
          required: false
          description: Metrics window. Required with `include=metrics`.
          name: period
          in: query
      responses:
        '200':
          description: The test case
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestCase'
        '400':
          description: '`VALIDATION_FAILED`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: '`AUTHENTICATION_REQUIRED` | `INVALID_TOKEN`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: '`TEST_CASE_NOT_FOUND`'
          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:
    TestCase:
      allOf:
        - $ref: '#/components/schemas/TestCaseSummary'
        - type: object
          properties:
            quarantineOverride:
              anyOf:
                - $ref: '#/components/schemas/QuarantineOverride'
                - type: 'null'
              description: >-
                The override currently in effect on this test, or null if none
                is.
            activeMonitors:
              type: array
              items:
                $ref: '#/components/schemas/ActiveMonitor'
              maxItems: 100
              description: The monitors currently classifying this test.
            firstSeenAt:
              type:
                - string
                - 'null'
              format: date-time
              description: >-
                When the test was first ingested. Null for tests last seen
                before Trunk began recording this, which is not backfilled.
              example: '2026-05-20T08:00:00.000Z'
            lastFailureAt:
              type:
                - string
                - 'null'
              format: date-time
              description: >-
                The most recent failing run Trunk still holds metrics for. Null
                if the test has never failed within that window.
              example: '2026-06-10T12:30:00.000Z'
          required:
            - quarantineOverride
            - activeMonitors
            - firstSeenAt
            - lastFailureAt
    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.
    TestCaseSummary:
      type: object
      properties:
        id:
          type: string
          description: >-
            The test case's globally unique id. Stable across repos and
            collections, and safe to store.
          example: bfeebcf4-0000-8000-8000-000000000001
        testCollectionId:
          type: string
          description: The owning collection's id.
          example: aB3xY9kQ
        repoId:
          type: string
          description: >-
            The repository the test was uploaded for. The nil UUID for uploads
            made without a repository.
          example: 7a2b3c4d-5e6f-4a1b-8c9d-0e1f2a3b4c5d
        name:
          type: string
          example: suite::test_case_name
        parentName:
          type: string
          example: Foo
        className:
          type: string
          example: FooSuite
        file:
          type: string
          example: src/foo.test.ts
        target:
          type: string
          description: The build target that ran the test, when one was reported.
          example: //src:foo_test
        variant:
          type: string
          example: ''
        crossVariantId:
          type:
            - string
            - 'null'
          description: Groups the same test across variants, when it has any.
          example: 5d4c3b2a-1f0e-4a1b-8c9d-0e1f2a3b4c5d
        codeowners:
          type: array
          items:
            type: string
          maxItems: 1000
          example:
            - '@team-a'
        status:
          $ref: '#/components/schemas/TestStatus'
        quarantineState:
          $ref: '#/components/schemas/QuarantineState'
        labels:
          type: array
          items:
            $ref: '#/components/schemas/Label'
          maxItems: 100
        metrics:
          anyOf:
            - $ref: '#/components/schemas/TestCaseMetrics'
            - type: 'null'
          description: >-
            Returned only when `include=metrics` is set. Null when the test had
            no runs in `period`.
      required:
        - id
        - testCollectionId
        - repoId
        - name
        - parentName
        - className
        - file
        - target
        - variant
        - crossVariantId
        - codeowners
        - status
        - quarantineState
        - labels
    QuarantineOverride:
      type: object
      properties:
        mode:
          $ref: '#/components/schemas/QuarantineMode'
        reason:
          type:
            - string
            - 'null'
          example: flaky in CI
        createdAt:
          type: string
          format: date-time
          example: '2026-06-05T00:00:00.000Z'
      required:
        - mode
        - reason
        - createdAt
    ActiveMonitor:
      type: object
      properties:
        monitorId:
          type:
            - string
            - 'null'
          description: Null for `manual`, which has no monitor resource.
          example: 1a2b3c4d-5e6f-4a1b-8c9d-0e1f2a3b4c5d
        monitorType:
          $ref: '#/components/schemas/ActiveMonitorType'
      required:
        - monitorId
        - monitorType
      description: >-
        A monitor watching this test. Includes types that never affect its
        status.
    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
    TestStatus:
      type: string
      enum:
        - healthy
        - flaky
        - broken
      description: >-
        A test's current composite status, reconciled across every active
        monitor.
      example: flaky
    QuarantineState:
      type: string
      enum:
        - quarantined
        - notQuarantined
      description: >-
        Whether the test is currently quarantined, derived from its status, the
        collection's quarantine settings and any override.
      example: notQuarantined
    Label:
      type: object
      properties:
        id:
          type: string
          example: 2b3c4d5e-6f70-4a1b-8c9d-0e1f2a3b4c5d
        name:
          type: string
          example: slow-on-prs
        color:
          type: string
          example: '#4F46E5'
        description:
          type: string
          example: Tests that only get slow on pull-request runs.
        createdAt:
          type: string
          format: date-time
          example: '2026-05-01T00:00:00.000Z'
      required:
        - id
        - name
        - color
        - description
        - createdAt
    TestCaseMetrics:
      type: object
      properties:
        failureRate:
          type: number
          description: Failing runs over total runs in the period, 0 to 1.
          example: 0.25
        prsImpacted:
          type: integer
          description: >-
            Distinct pull requests that saw this test fail while it was
            unhealthy and not quarantined.
          example: 3
        runCount:
          type: integer
          example: 40
        failureCount:
          type: integer
          example: 10
        durationP95Ms:
          type:
            - integer
            - 'null'
          description: >-
            95th-percentile duration in milliseconds. Null when nothing
            measurable ran in the period — skipped runs are not measured.
          example: 1200
        lastRunAt:
          type:
            - string
            - 'null'
          format: date-time
          example: '2026-06-02T10:00:00.000Z'
        lastFailureAt:
          type:
            - string
            - 'null'
          format: date-time
          description: Within the period, unlike the test case's own field.
          example: '2026-06-01T10:00:00.000Z'
      required:
        - failureRate
        - prsImpacted
        - runCount
        - failureCount
        - durationP95Ms
        - lastRunAt
        - lastFailureAt
    QuarantineMode:
      type: string
      enum:
        - alwaysQuarantine
        - neverQuarantine
      description: A per-test quarantine override.
      example: alwaysQuarantine
    ActiveMonitorType:
      type: string
      enum:
        - failureRate
        - passOnRetry
        - failureCount
        - newTest
        - skippedTest
        - slowTest
        - timeoutInflation
        - manual
      description: >-
        A monitor type that can be active on a test. `manual` is the 'flag as
        flaky' mark, which has no addressable monitor resource and always
        reports a null `monitorId`.
      example: failureRate
  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.

````