# Search issues and pull requests

From **GitHub v3 REST API**.

`GET /search/issues`

Find issues by state and keyword. This method returns up to 100 results [per page](https://docs.github.com/enterprise-server@3.0/rest/overview/resources-in-the-rest-api#pagination).

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](https://docs.github.com/enterprise-server@3.0/rest/reference/search#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](https://docs.github.com/developers/apps/identifying-and-authorizing-users-for-github-apps#user-to-server-requests) 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](https://docs.github.com/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-only-issues-or-pull-requests)."

## Parameters

### `q`

- Location: query
- Required: true
- Type: `string`

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](https://docs.github.com/enterprise-server@3.0/rest/reference/search#constructing-a-search-query). See "[Searching issues and pull requests](https://docs.github.com/articles/searching-issues-and-pull-requests/)" for a detailed list of qualifiers.

### `sort`

- Location: query
- Required: false
- Type: `string`
- Allowed values: `"comments"`, `"reactions"`, `"reactions-+1"`, `"reactions--1"`, `"reactions-smile"`, `"reactions-thinking_face"`, `"reactions-heart"`, `"reactions-tada"`, `"interactions"`, `"created"`, `"updated"`

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](https://docs.github.com/enterprise-server@3.0/rest/reference/search#ranking-search-results)

### `order`

- Location: query
- Required: false
- Type: `string`
- Default: `desc`
- Allowed values: `"desc"`, `"asc"`

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`.

### `per_page`

- Location: query
- Required: false
- Type: `integer`
- Default: `30`

Results per page (max 100)

### `page`

- Location: query
- Required: false
- Type: `integer`
- Default: `1`

Page number of the results to fetch.

## Responses

### `200`

Response

### `application/json`

- Type: `object`

```json
{
  "incomplete_results": false,
  "items": [
    {
      "assignee": null,
      "author_association": "COLLABORATOR",
      "body": "...",
      "closed_at": null,
      "comments": 15,
      "comments_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/comments",
      "created_at": "2009-07-12T20:10:41Z",
      "events_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/events",
      "html_url": "https://github.com/batterseapower/pinyin-toolkit/issues/132",
      "id": 35802,
      "labels": [
        {
          "color": "ff0000",
          "id": 4,
          "name": "bug",
          "node_id": "MDU6TGFiZWw0",
          "url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/labels/bug"
        }
      ],
      "labels_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132/labels{/name}",
      "locked": true,
      "milestone": {
        "closed_at": "2013-02-12T13:22:01Z",
        "closed_issues": 8,
        "created_at": "2011-04-10T20:09:31Z",
        "creator": {
          "avatar_url": "https://github.com/images/error/octocat_happy.gif",
          "events_url": "https://api.github.com/users/octocat/events{/privacy}",
          "followers_url": "https://api.github.com/users/octocat/followers",
          "following_url": "https://api.github.com/users/octocat/following{/other_user}",
          "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
          "gravatar_id": "",
          "html_url": "https://github.com/octocat",
          "id": 1,
          "login": "octocat",
          "node_id": "MDQ6VXNlcjE=",
          "organizations_url": "https://api.github.com/users/octocat/orgs",
          "received_events_url": "https://api.github.com/users/octocat/received_events",
          "repos_url": "https://api.github.com/users/octocat/repos",
          "site_admin": false,
          "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
          "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
          "type": "User",
          "url": "https://api.github.com/users/octocat"
        },
        "description": "Tracking milestone for version 1.0",
        "due_on": "2012-10-09T23:39:01Z",
        "html_url": "https://github.com/octocat/Hello-World/milestones/v1.0",
        "id": 1002604,
        "labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels",
        "node_id": "MDk6TWlsZXN0b25lMTAwMjYwNA==",
        "number": 1,
        "open_issues": 4,
        "state": "open",
        "title": "v1.0",
        "updated_at": "2014-03-03T18:58:10Z",
        "url": "https://api.github.com/repos/octocat/Hello-World/milestones/1"
      },
      "node_id": "MDU6SXNzdWUzNTgwMg==",
      "number": 132,
      "pull_request": {
        "diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
        "html_url": "https://github.com/octocat/Hello-World/pull/1347",
        "patch_url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
        "url": "https://api/github.com/repos/octocat/Hello-World/pull/1347"
      },
      "repository_url": "https://api.github.com/repos/batterseapower/pinyin-toolkit",
      "score": 1,
      "state": "open",
      "title": "Line Number Indexes Beyond 20 Not Displayed",
      "updated_at": "2009-07-19T09:23:43Z",
      "url": "https://api.github.com/repos/batterseapower/pinyin-toolkit/issues/132",
      "user": {
        "avatar_url": "https://secure.gravatar.com/avatar/934442aadfe3b2f4630510de416c5718?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
        "events_url": "https://api.github.com/users/Nick3C/events{/privacy}",
        "followers_url": "https://api.github.com/users/Nick3C/followers",
        "following_url": "https://api.github.com/users/Nick3C/following{/other_user}",
        "gists_url": "https://api.github.com/users/Nick3C/gists{/gist_id}",
        "gravatar_id": "",
        "html_url": "https://github.com/Nick3C",
        "id": 90254,
        "login": "Nick3C",
        "node_id": "MDQ6VXNlcjkwMjU0",
        "organizations_url": "https://api.github.com/users/Nick3C/orgs",
        "received_events_url": "https://api.github.com/users/Nick3C/received_events",
        "repos_url": "https://api.github.com/users/Nick3C/repos",
        "site_admin": true,
        "starred_url": "https://api.github.com/users/Nick3C/starred{/owner}{/repo}",
        "subscriptions_url": "https://api.github.com/users/Nick3C/subscriptions",
        "type": "User",
        "url": "https://api.github.com/users/Nick3C"
      }
    }
  ],
  "total_count": 280
}
```

```json
{"properties":{"incomplete_results":{"type":"boolean"},"items":{"items":{"$ref":"#/components/schemas/issue-search-result-item"},"type":"array"},"total_count":{"type":"integer"}},"required":["total_count","incomplete_results","items"],"type":"object"}
```

### `304`

Not modified

### `403`

Forbidden

### `application/json`

- Type: `object`

Basic Error

```json
{"description":"Basic Error","properties":{"documentation_url":{"type":"string"},"message":{"type":"string"},"status":{"type":"string"},"url":{"type":"string"}},"title":"Basic Error","type":"object"}
```

### `422`

Validation failed

### `application/json`

- Type: `object`

Validation Error

```json
{"description":"Validation Error","properties":{"documentation_url":{"type":"string"},"errors":{"items":{"properties":{"code":{"type":"string"},"field":{"type":"string"},"index":{"type":"integer"},"message":{"type":"string"},"resource":{"type":"string"},"value":{"oneOf":[{"nullable":true,"type":"string"},{"nullable":true,"type":"integer"},{"items":{"type":"string"},"nullable":true,"type":"array"}]}},"required":["code"],"type":"object"},"type":"array"},"message":{"type":"string"}},"required":["message","documentation_url"],"title":"Validation Error","type":"object"}
```

### `503`

Service unavailable

### `application/json`

- Type: `object`

```json
{"properties":{"code":{"type":"string"},"documentation_url":{"type":"string"},"message":{"type":"string"}},"type":"object"}
```

## Request examples

### cURL

```shell
curl --request GET \
  --url {protocol}://{hostname}/api/v3/search/issues
```
