Sample - GitHub REST API
PUT/repos/{owner}/{repo}/pulls/{pull_number}/merge-async

Merge a pull request asynchronously

Merges a pull request into the base branch in the background. Merging in this way allows certain types of errors to be retried, and avoids the risk of timeouts for particularly complex merges.

This is the required method for merging stacked PRs, but also supports unstacked PRs. When using this endpoint to merge a stacked pull request, all pull requests in the stack up to and including the requested PR will be merged into the base branch.

The response includes a UUID that can be used to fetch the result of the merge. If another asynchronous merge request has already been made for this pull request, the UUID of that request will be returned instead with a 409 response status to indicate that the merge options may be different from those that were requested. If there isn't an existing asynchronous merge request, a 202 response status is used.

If the pull request is already merged, the merge commit OID will be returned immediately with a 200 status.

If the pull request cannot be merged (e.g. because it is closed, or still a draft) this result will be returned immediately with a 400 response status. Branch protection rules and repository rules are not run at this stage, only basic pull request state checks are performed.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

3 parameters · 5 body fields
ownerstringrequired
The account owner of the repository. The name is not case sensitive.
repostringrequired
The name of the repository without the `.git` extension. The name is not case sensitive.
pull_numberintegerrequired
The number that identifies the pull request.
commit_titlestringoptional
Title for the automatic commit message.
commit_messagestringoptional
Extra detail to append to automatic commit message.
shastringoptional
SHA that pull request head must match to allow merge. If not provided, the current head of the PR at the time of the request will be used; if the PR is pushed in between the merge being requested and being executed, the merge will be cancelled.
merge_methodstringoptional
The merge method to use.
Allowed:mergesquashrebase
merge_actionstringoptional
The action that will be taken to merge the pull request. `direct_merge` merges the pull request directly without using a merge queue; `merge_queue` adds the pull request to a merge queue; `default` selects the most appropriate option.
Allowed:defaultdirect_mergemerge_queue

7 status codes
200if the pull request was already merged, or is already in a merge queue
statusstringrequired
Allowed:pendingmergedenqueuedfailed
detailsobjectrequired
When an asynchronous merge request was created or already existed
202if the merge request was accepted and will run in the background
statusstringrequired
Allowed:pendingmergedenqueuedfailed
detailsobjectrequired
When an asynchronous merge request was created or already existed
400if the pull request is not ready to be merged, e.g. because it is closed
statusstringrequired
Allowed:pendingmergedenqueuedfailed
detailsobjectrequired
When an asynchronous merge request was created or already existed
403Forbidden
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
404Resource not found
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
409if there is an existing merge request already enqueued for this pull request
statusstringrequired
Allowed:pendingmergedenqueuedfailed
detailsobjectrequired
When an asynchronous merge request was created or already existed
422Validation failed, or the endpoint has been spammed.
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional

Error handling

A 400 is returned: if the pull request is not ready to be merged, e.g. because it is closed. A 403 is returned: Forbidden. A 404 is returned: Resource not found. A 409 is returned: if there is an existing merge request already enqueued for this pull request. A 422 is returned: Validation failed, or the endpoint has been spammed.