GitHub v3 REST API

Search code

Searches for query terms inside of a file. This method returns up to 100 results per page.

When searching for code, you can get text match metadata for the file content and file path fields when you pass the text-match media type. For more details about how to receive highlighted search results, see Text match metadata.

For example, if you want to find the definition of the addClass function inside jQuery repository, your query would look something like this:

q=addClass+in:file+language:js+repo:jquery/jquery

This query searches for the keyword addClass within a file’s contents. The query limits the search to files where the language is JavaScript in the jquery/jquery repository.

Considerations for code search

Due to the complexity of searching code, there are a few restrictions on how searches are performed:

  • Only the default branch is considered. In most cases, this will be the master branch.
  • Only files smaller than 384 KB are searchable.
  • You must always include at least one search term when searching source code. For example, searching for language:go is not valid, while amazing language:go is.
get
http://HOSTNAME/api/v3/search/code

Query Parameters

qstringrequired

The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see Constructing a search query. See “Searching code” for a detailed list of qualifiers.

sortstring

Sorts the results of your query. Can only be indexed, which indicates how recently a file has been indexed by the GitHub Enterprise Server search infrastructure. Default: best match

Allowed values:indexed

orderstring

Determines whether the first search result returned is the highest number of matches (desc) or lowest number of matches (asc). This parameter is ignored unless you provide sort.

Allowed values:descasc

Default:desc

per_pageinteger

Results per page (max 100)

Default:30

pageinteger

Page number of the results to fetch.

Default:1

Response

application/json

Response

total_countintegerrequired
incomplete_resultsbooleanrequired
itemsarray[object]required

Code Search Result Item

Show Child Parameters
get/search/code
 
application/json

Search commits

Find commits via various criteria on the default branch (usually master). This method returns up to 100 results per page.

When searching for commits, you can get text match metadata for the message field when you provide the text-match media type. For more details about how to receive highlighted search results, see Text match
metadata
.

For example, if you want to find commits related to CSS in the octocat/Spoon-Knife repository. Your query would look something like this:

q=repo:octocat/Spoon-Knife+css

get
http://HOSTNAME/api/v3/search/commits

Query Parameters

qstringrequired

The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see Constructing a search query. See “Searching commits” for a detailed list of qualifiers.

sortstring

Sorts the results of your query by author-date or committer-date. Default: best match

Allowed values:author-datecommitter-date

orderstring

Determines whether the first search result returned is the highest number of matches (desc) or lowest number of matches (asc). This parameter is ignored unless you provide sort.

Allowed values:descasc

Default:desc

per_pageinteger

Results per page (max 100)

Default:30

pageinteger

Page number of the results to fetch.

Default:1

Response

application/json

Response

total_countintegerrequired
incomplete_resultsbooleanrequired
itemsarray[object]required

Commit Search Result Item

Show Child Parameters
get/search/commits
 
application/json

Search issues and pull requests

Find issues by state and keyword. This method returns up to 100 results per page.

When searching for issues, you can get text match metadata for the issue title, issue body, and issue comment body fields when you pass the text-match media type. For more details about how to receive highlighted
search results, see Text match metadata.

For example, if you want to find the oldest unresolved Python bugs on Windows. Your query might look something like this.

q=windows+label:bug+language:python+state:open&sort=created&order=asc

This query searches for the keyword windows, within any open issue that is labeled as bug. The search runs across repositories whose primary language is Python. The results are sorted by creation date in ascending order, which means the oldest issues appear first in the search results.

Note: For user-to-server GitHub App requests, you can’t retrieve a combination of issues and pull requests in a single query. Requests that don’t include the is:issue or is:pull-request qualifier will receive an HTTP 422 Unprocessable Entity response. To get results for both issues and pull requests, you must send separate queries for issues and pull requests. For more information about the is qualifier, see “Searching only issues or pull requests.”

get
http://HOSTNAME/api/v3/search/issues

Query Parameters

qstringrequired

The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see Constructing a search query. See “Searching issues and pull requests” for a detailed list of qualifiers.

sortstring

Sorts the results of your query by the number of comments, reactions, reactions-+1, reactions--1, reactions-smile, reactions-thinking_face, reactions-heart, reactions-tada, or interactions. You can also sort results by how recently the items were created or updated, Default: best match

Allowed values:commentsreactionsreactions-+1reactions--1reactions-smilereactions-thinking_facereactions-heartreactions-tadainteractionscreatedupdated

orderstring

Determines whether the first search result returned is the highest number of matches (desc) or lowest number of matches (asc). This parameter is ignored unless you provide sort.

Allowed values:descasc

Default:desc

per_pageinteger

Results per page (max 100)

Default:30

pageinteger

Page number of the results to fetch.

Default:1

Response

application/json

Response

total_countintegerrequired
incomplete_resultsbooleanrequired
itemsarray[object]required

Issue Search Result Item

Show Child Parameters
get/search/issues
 
application/json

Search labels

Find labels in a repository with names or descriptions that match search keywords. Returns up to 100 results per page.

When searching for labels, you can get text match metadata for the label name and description fields when you pass the text-match media type. For more details about how to receive highlighted search results, see Text match metadata.

For example, if you want to find labels in the linguist repository that match bug, defect, or enhancement. Your query might look like this:

q=bug+defect+enhancement&repository_id=64778136

The labels that best match the query appear first in the search results.

get
http://HOSTNAME/api/v3/search/labels

Query Parameters

repository_idintegerrequired

The id of the repository.

qstringrequired

The search keywords. This endpoint does not accept qualifiers in the query. To learn more about the format of the query, see Constructing a search query.

sortstring

Sorts the results of your query by when the label was created or updated. Default: best match

Allowed values:createdupdated

orderstring

Determines whether the first search result returned is the highest number of matches (desc) or lowest number of matches (asc). This parameter is ignored unless you provide sort.

Allowed values:descasc

Default:desc

per_pageinteger

Results per page (max 100)

Default:30

pageinteger

Page number of the results to fetch.

Default:1

Response

application/json

Response

total_countintegerrequired
incomplete_resultsbooleanrequired
itemsarray[object]required

Label Search Result Item

Show Child Parameters
get/search/labels
 
application/json

Search repositories

Find repositories via various criteria. This method returns up to 100 results per page.

When searching for repositories, you can get text match metadata for the name and description fields when you pass the text-match media type. For more details about how to receive highlighted search results, see Text match metadata.

For example, if you want to search for popular Tetris repositories written in assembly code, your query might look like this:

q=tetris+language:assembly&sort=stars&order=desc

This query searches for repositories with the word tetris in the name, the description, or the README. The results are limited to repositories where the primary language is assembly. The results are sorted by stars in descending order, so that the most popular repositories appear first in the search results.

When you include the mercy preview header, you can also search for multiple topics by adding more topic: instances. For example, your query might look like this:

q=topic:ruby+topic:rails

get
http://HOSTNAME/api/v3/search/repositories

Query Parameters

qstringrequired

The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub. The REST API supports the same qualifiers as GitHub.com. To learn more about the format of the query, see Constructing a search query. See “Searching for repositories” for a detailed list of qualifiers.

sortstring

Sorts the results of your query by number of stars, forks, or help-wanted-issues or how recently the items were updated. Default: best match

Allowed values:starsforkshelp-wanted-issuesupdated

orderstring

Determines whether the first search result returned is the highest number of matches (desc) or lowest number of matches (asc). This parameter is ignored unless you provide sort.

Allowed values:descasc

Default:desc

per_pageinteger

Results per page (max 100)

Default:30

pageinteger

Page number of the results to fetch.

Default:1

Response

application/json

Response

total_countintegerrequired
incomplete_resultsbooleanrequired
itemsarray[object]required

Repo Search Result Item

Show Child Parameters
get/search/repositories
 
application/json