Sample - GitHub REST API
POST/repos/{owner}/{repo}/pulls

Create a pull request

Draft pull requests are available in public repositories with GitHub Free and GitHub Free for organizations, GitHub Pro, and legacy per-repository billing plans, and in public and private repositories with GitHub Team and GitHub Enterprise Cloud. For more information, see GitHub's products in the GitHub Help documentation.

To open or update a pull request in a public repository, you must have write access to the head or the source branch. For organization-owned repositories, you must be a member of the organization that owns the repository to open or update a pull request.

This endpoint triggers notifications. Creating content too quickly using this endpoint may result in secondary rate limiting. For more information, see "Rate limits for the API" and "Best practices for using the REST API."

This endpoint supports the following custom media types. For more information, see "Media types."

  • application/vnd.github.raw+json: Returns the raw markdown body. Response will include body. This is the default if you do not pass any specific media type.
  • application/vnd.github.text+json: Returns a text only representation of the markdown body. Response will include body_text.
  • application/vnd.github.html+json: Returns HTML rendered from the body's markdown. Response will include body_html.
  • application/vnd.github.full+json: Returns raw, text, and HTML representations. Response will include body, body_text, and body_html.
  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

2 parameters · 8 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.
titlestringoptional
The title of the new pull request. Required unless `issue` is specified.
headstringrequired
The name of the branch where your changes are implemented. For cross-repository pull requests in the same network, namespace `head` with a user like this: `username:branch`.
head_repostringoptional
The name of the repository where the changes in the pull request were made. This field is required for cross-repository pull requests if both repositories are owned by the same organization.
basestringrequired
The name of the branch you want the changes pulled into. This should be an existing branch on the current repository. You cannot submit a pull request to one repository that requests a merge to a base of another repository.
bodystringoptional
The contents of the pull request.
maintainer_can_modifybooleanoptional
Indicates whether [maintainers can modify](https://docs.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/) the pull request.
draftbooleanoptional
Indicates whether the pull request is a draft. See "[Draft Pull Requests](https://docs.github.com/articles/about-pull-requests#draft-pull-requests)" in the GitHub Help documentation to learn more.
issueintegeroptional
An issue in the repository to convert to a pull request. The issue title, body, and comments will become the title, body, and comments on the new pull request. Required unless `title` is specified.

3 status codes
201Response
urlstringrequired
idintegerrequired
node_idstringrequired
html_urlstringrequired
diff_urlstringrequired
patch_urlstringrequired
issue_urlstringrequired
commits_urlstringrequired
review_comments_urlstringrequired
review_comment_urlstringrequired
comments_urlstringrequired
statuses_urlstringrequired
numberintegerrequired
Number uniquely identifying the pull request within its repository.
statestringrequired
State of this Pull Request. Either `open` or `closed`.
Allowed:openclosed
lockedbooleanrequired
titlestringrequired
The title of the pull request.
userobjectrequired
A GitHub user.
bodystringrequired
labelsarray<object>required
milestoneobjectrequired
A collection of related issues and pull requests.
active_lock_reasonstringoptional
created_atstringrequired
updated_atstringrequired
closed_atstringrequired
merged_atstringrequired
merge_commit_shastringrequired
assigneeobjectrequired
A GitHub user.
assigneesarray<SimpleUser>optional
requested_reviewersarray<SimpleUser>optional
requested_teamsarray<TeamSimple>optional
headobjectrequired
baseobjectrequired
_linksobjectrequired
author_associationstringrequired
How the author is associated with the repository.
Allowed:COLLABORATORCONTRIBUTORFIRST_TIMERFIRST_TIME_CONTRIBUTORMANNEQUINMEMBERNONEOWNER
auto_mergeobjectrequired
The status of auto merging a pull request.
stackobjectoptional
The stack information associated with a pull request.
draftbooleanoptional
Indicates whether or not the pull request is a draft.
mergedbooleanrequired
mergeablebooleanrequired
rebaseablebooleanoptional
mergeable_statestringrequired
merged_byobjectrequired
A GitHub user.
commentsintegerrequired
review_commentsintegerrequired
maintainer_can_modifybooleanrequired
Indicates whether maintainers can modify the pull request.
commitsintegerrequired
additionsintegerrequired
deletionsintegerrequired
changed_filesintegerrequired
403Forbidden
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
422Validation failed, or the endpoint has been spammed.
messagestringrequired
documentation_urlstringrequired
errorsarray<object>optional

Error handling

A 403 is returned: Forbidden. A 422 is returned: Validation failed, or the endpoint has been spammed.