# List code scanning analyses for a repository

From **GitHub v3 REST API**.

`GET /repos/{owner}/{repo}/code-scanning/analyses`

Lists the details of all code scanning analyses for a repository,
starting with the most recent.
The response is paginated and you can use the `page` and `per_page` parameters
to list the analyses you're interested in.
By default 30 analyses are listed per page.

The `rules_count` field in the response give the number of rules
that were run in the analysis.
For very old analyses this data is not available,
and `0` is returned in this field.

You must use an access token with the `security_events` scope to use this endpoint.
GitHub Apps must have the `security_events` read permission to use this endpoint.

**Deprecation notice**:
The `tool_name` field is deprecated and will, in future, not be included in the response for this endpoint. The example response reflects this change. The tool name can now be found inside the `tool` field.

## Parameters

### `owner`

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

### `repo`

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

### `tool_name`

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

The name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either `tool_name` or `tool_guid`, but not both.

### `tool_guid`

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

The GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either `tool_guid` or `tool_name`, but not both.

### `page`

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

Page number of the results to fetch.

### `per_page`

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

Results per page (max 100)

### `ref`

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

The Git reference for the analyses you want to list. The `ref` for a branch can be formatted either as `refs/heads/<branch name>` or simply `<branch name>`. To reference a pull request use `refs/pull/<number>/merge`.

### `sarif_id`

- Location: query
- Required: false
- Type: `string`
- Example: `6c81cd8e-b078-4ac3-a3be-1dad7dbd0b53`

Filter analyses belonging to the same SARIF upload.

## Responses

### `200`

Response

### `application/json`

- Type: `array`

```json
[
  {
    "analysis_key": ".github/workflows/codeql-analysis.yml:analyze",
    "category": ".github/workflows/codeql-analysis.yml:analyze/language:python",
    "commit_sha": "d99612c3e1f2970085cfbaeadf8f010ef69bad83",
    "created_at": "2020-08-27T15:05:21Z",
    "deletable": true,
    "environment": "{\"language\":\"python\"}",
    "error": "",
    "id": 201,
    "ref": "refs/heads/main",
    "results_count": 17,
    "rules_count": 49,
    "sarif_id": "6c81cd8e-b078-4ac3-a3be-1dad7dbd0b53",
    "tool": {
      "guid": null,
      "name": "CodeQL",
      "version": "2.4.0"
    },
    "url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/201",
    "warning": ""
  },
  {
    "analysis_key": ".github/workflows/shiftleft.yml:build",
    "category": ".github/workflows/shiftleft.yml:build/",
    "commit_sha": "c8cff6510d4d084fb1b4aa13b64b97ca12b07321",
    "created_at": "2020-08-31T22:46:44Z",
    "deletable": true,
    "environment": "{}",
    "error": "",
    "id": 200,
    "ref": "refs/heads/my-branch",
    "results_count": 17,
    "rules_count": 32,
    "sarif_id": "8981cd8e-b078-4ac3-a3be-1dad7dbd0b582",
    "tool": {
      "guid": null,
      "name": "Python Security Analysis",
      "version": "1.2.0"
    },
    "url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/200",
    "warning": ""
  }
]
```

```json
{"items":{"$ref":"#/components/schemas/code-scanning-analysis"},"type":"array"}
```

### `403`

Response if GitHub Advanced Security is not enabled for this repository

### `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"}
```

### `404`

Resource not found

### `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"}
```

### `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/repos/{owner}/{repo}/code-scanning/analyses
```
