API / merge-origin-pull-request-via-api

API

Merge an Origin Pull Request via the API

Merge a pull request into its base with POST https://api.cursor.com/v1/origin/repos/{ownerSlug}/{repoName}/pulls/{pullNumber}/merge. Official reference: Origin API → Merge Pull Request (OpenAPI OriginService_MergePullRequest). Changelog notes: September 10, 2026 (optional mergeMethod), August 21, 2026 (optional expectedHeadSha).

Origin is in Early Beta and subject to change. Authenticate with an installation access token (oit_…) or a user access token that carries repository:contents:write. Availability: Early Beta per the API overview.

Supported only on native Origin repositories; mirrored repositories are rejected. For a stacked pull request, the merge lands every pull from the stack root through this number — not only this pull. Pull request number is a JSON string (protobuf 64-bit encoding).

Cost: 10 points against the principal budget.

Path parameters

Param Required Meaning
ownerSlug yes Owning entity's unique slug
repoName yes Repo name, unique to the owner
pullNumber yes Pull number to merge; when stacked, merges the root-to-target prefix ending here

Request body

Send a JSON object (may be empty {}).

Field Required Meaning
expectedHeadSha no Full commit SHA (40- or 64-character hex) expected as the current head. When set and the head has moved, the merge is rejected with ABORTED (HTTP 409 Conflict) and nothing merges. Values that are not a full commit SHA return INVALID_ARGUMENT. Not evaluated when the pull is already merged (idempotent success). Omit to merge the current head
mergeMethod no merge writes a merge commit; squash writes a single squash commit. A method the repository does not allow fails with FAILED_PRECONDITION. Omit to use the repository default: merge commit when allowed, otherwise squash; squash when the base branch requires linear history
curl --request POST \
  --url 'https://api.cursor.com/v1/origin/repos/OWNER_SLUG/REPO_NAME/pulls/17/merge' \
  --header 'Authorization: Bearer YOUR_ORIGIN_TOKEN' \
  --header 'Content-Type: application/json' \
  --data '{
  "expectedHeadSha": "9a41f0c3d2b8e7f6a5c4d3e2f1b0a9c8d7e6f5a4",
  "mergeMethod": "squash"
}'

Response

200 returns a MergePullRequestResponse: mergeCommitSha, mergedPullNumbers (root-to-target order; empty when the prefix was already merged), and the target pullRequest after the merge.

{
  "mergeCommitSha": "5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b7c6d",
  "mergedPullNumbers": [
    "17"
  ],
  "pullRequest": {
    "id": "pr_01k2ja2000e0080000000000d4",
    "number": "17",
    "state": "closed",
    "draft": false,
    "merged": true,
    "title": "Add launch telemetry",
    "body": "Adds structured launch telemetry to the ignition path.",
    "head": {
      "ref": "add-telemetry",
      "sha": "9a41f0c3d2b8e7f6a5c4d3e2f1b0a9c8d7e6f5a4"
    },
    "base": {
      "ref": "main",
      "sha": "3b1f9c2d8a7e6f5049c8b7a6d5e4f3a2b1c0d9e8"
    },
    "author": {
      "user": {
        "id": "user_01k2ja2000e0080000000000c3",
        "email": "jane@acme.dev"
      }
    },
    "createdAt": "2026-08-01T09:30:00Z",
    "updatedAt": "2026-08-02T14:45:00Z",
    "closedAt": "2026-08-03T10:15:00Z",
    "mergedAt": "2026-08-03T10:15:00Z",
    "mergeCommitSha": "5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b7c6d",
    "additions": 128,
    "deletions": 46,
    "changedFiles": 5,
    "labels": [
      {
        "id": "lbl_01k2ja2000e0080000000000m1",
        "name": "bug",
        "color": "d73a4a",
        "description": "Something isn't working"
      }
    ],
    "version": {
      "number": "3",
      "headSha": "9a41f0c3d2b8e7f6a5c4d3e2f1b0a9c8d7e6f5a4",
      "baseSha": "3b1f9c2d8a7e6f5049c8b7a6d5e4f3a2b1c0d9e8",
      "createdAt": "2026-08-01T09:30:00Z"
    }
  }
}

Parse every pull number as a string. Check merge readiness first with Get Pull Request Mergeability when you need typed blockers. Base URL: https://api.cursor.com/v1/origin.