Skip to main content

Documentation Index

Fetch the complete documentation index at: https://trunk-4cab4936-sam-gutentag-flaky-tests-new-monitors.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

The Trunk Merge Queue API lets you manage pull requests, configure queues, and monitor queue health programmatically. Use it to integrate merge queue operations into your CI/CD pipelines, build custom dashboards, or automate queue management across repositories. The API is an HTTP REST API hosted at https://api.trunk.io/v1. It returns JSON from all requests and uses standard HTTP response codes. All requests must be authenticated by providing the x-api-token header.

Endpoint summary

EndpointMethodDescription
/submitPullRequestPOSTSubmit a PR to the merge queue for testing and merging
/cancelPullRequestPOSTRemove a PR from the merge queue
/restartTestsOnPullRequestPOSTRe-run tests on a PR currently in the queue
/getSubmittedPullRequestPOSTCheck the status of a submitted PR
/setImpactedTargetsPOSTSet impacted targets for a PR (used with parallel queues)
/getMergeQueueTestingDetailsPOSTGet details about in-progress merge queue testing
/createQueuePOSTCreate a new merge queue for a branch
/deleteQueuePOSTDelete an empty merge queue
/getQueuePOSTGet queue state, configuration, and enqueued PRs
/updateQueuePOSTUpdate queue configuration (mode, concurrency, batching, etc.)
/getMergeQueueMetricsGETGet Prometheus-format metrics for monitoring

Common use cases

CI/CD automation — Submit PRs to the queue, check their status, and restart tests automatically from your CI pipelines. Queue management — Create and configure queues for different branches, adjust concurrency and batching settings, or pause and drain queues during maintenance windows. Monitoring dashboards — Use the Prometheus metrics endpoint to build custom Grafana dashboards or feed queue health data into your existing observability stack. PR status checks — Query the status of submitted PRs to build custom notifications or gate downstream workflows.

Request format

Request bodies must not exceed 20 MiB. Most endpoints accept a JSON request body with these common fields:
{
  "repo": {
    "host": "github.com",
    "owner": "my-org",
    "name": "my-repo"
  },
  "targetBranch": "main",
  "pr": {
    "number": 123
  }
}
FieldTypeRequiredDescription
repo.hoststringYesRepository host (e.g., github.com)
repo.ownerstringYesRepository owner or organization
repo.namestringYesRepository name
targetBranchstringYesThe branch the merge queue targets
pr.numberintegerVariesThe pull request number (required for PR endpoints)

Examples

Submit a PR to the queue

curl -X POST https://api.trunk.io/v1/submitPullRequest \
  -H "Content-Type: application/json" \
  -H "x-api-token: $TRUNK_API_TOKEN" \
  -d '{
    "repo": {
      "host": "github.com",
      "owner": "my-org",
      "name": "my-repo"
    },
    "targetBranch": "main",
    "pr": {
      "number": 123
    }
  }'

Check PR status

curl -X POST https://api.trunk.io/v1/getSubmittedPullRequest \
  -H "Content-Type: application/json" \
  -H "x-api-token: $TRUNK_API_TOKEN" \
  -d '{
    "repo": {
      "host": "github.com",
      "owner": "my-org",
      "name": "my-repo"
    },
    "targetBranch": "main",
    "pr": {
      "number": 123
    }
  }'
The response includes the PR state (NOT_READY, PENDING, TESTING, TESTS_PASSED, MERGED, FAILED, CANCELLED, or PENDING_FAILURE), priority information, and whether the PR is currently submitted to the queue.

Get queue state

curl -X POST https://api.trunk.io/v1/getQueue \
  -H "Content-Type: application/json" \
  -H "x-api-token: $TRUNK_API_TOKEN" \
  -d '{
    "repo": {
      "host": "github.com",
      "owner": "my-org",
      "name": "my-repo"
    },
    "targetBranch": "main"
  }'
The response includes the queue state (RUNNING, PAUSED, DRAINING, or SWITCHING_MODES), configuration settings, and a list of all enqueued pull requests with their current states.

Pull request endpoints

Cancel a pull request in a merge queue

Get a submitted pull request from a merge queue

Restart tests on a pull request in a merge queue

Set impacted targets for a pull request

Submit a pull request to a merge queue

Get details about testing that Merge Queue is performing

Large monorepos can produce target lists that exceed the 20 MiB request body limit. If you hit this limit, send "ALL" as the impactedTargets value to mark the PR as impacting every target.

Metrics endpoints

Prometheus metrics

Prometheus metrics

GET /v1/getMergeQueueMetrics Returns merge queue metrics in Prometheus text exposition format. Authenticate with the x-api-token header.
ParameterRequiredDescription
repoNoRepository in owner/name format. If omitted, returns metrics for all repositories in the organization. Must be provided together with repoHost.
repoHostConditionalRepository host (e.g., github.com). Required if repo is specified.
Response content type: text/plain; version=0.0.4; charset=utf-8 See Prometheus metrics endpoint for the full list of available metrics, scrape configuration, and example queries.

Queue endpoints

Use these endpoints to create, configure, and manage merge queues. Each queue targets a specific branch in your repository. For more on running multiple queues, see parallel queues.

Create a new merge queue.

Delete the specified merge queue. The queue must be empty in order to be deleted.

Get the merge queue.

Update the merge queue.

The queue must be empty before it can be deleted. Cancel or merge all enqueued PRs first.