---
title: Get per-file code coverage data
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Code Coverage
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Get per-file code coverage data{% #get-per-file-code-coverage-data %}
Copy pageCopied
{% tab title="v2" %}

| Datadog site      | API endpoint                                                  |
| ----------------- | ------------------------------------------------------------- |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/code-coverage/files |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/code-coverage/files |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/code-coverage/files      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/code-coverage/files      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/code-coverage/files  |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/code-coverage/files |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/code-coverage/files     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/code-coverage/files |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/code-coverage/files |

### Overview

Retrieve per-file code coverage data for a specific commit, branch, or pull request. Exactly one of `commit_sha`, `branch`, or `pr_number` must be provided. Optionally filter by `service`, `codeowner`, or `flag` (at most one). This endpoint requires the `code_coverage_read` permission.

OAuth apps require the `code_coverage_read` authorization [scope](https://docs.datadoghq.com/api/latest/scopes.md#code-coverage) to access this endpoint.



### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field | Field                        | Type    | Description                                                                                                                                                                                      |
| ------------ | ---------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|              | data [*required*]       | object  | Data object for files coverage request.                                                                                                                                                          |
| data         | attributes [*required*] | object  | Attributes for requesting per-file code coverage data. Exactly one of `commit_sha`, `branch`, or `pr_number` must be provided. At most one of `service`, `codeowner`, or `flag` may be provided. |
| attributes   | branch                       | string  | The branch name.                                                                                                                                                                                 |
| attributes   | changed_only                 | boolean | When true, return coverage data only for files that were changed in the specified scope.                                                                                                         |
| attributes   | codeowner                    | string  | Filter coverage by code owner. At most one of `service`, `codeowner`, or `flag` may be provided.                                                                                                 |
| attributes   | commit_sha                   | string  | The commit SHA (40-character hexadecimal string).                                                                                                                                                |
| attributes   | flag                         | string  | Filter coverage by coverage flag. At most one of `service`, `codeowner`, or `flag` may be provided.                                                                                              |
| attributes   | pr_number                    | int64   | The pull request number. Must be a positive integer.                                                                                                                                             |
| attributes   | repository_id                | string  | **DEPRECATED**: Deprecated: use `repository_url` instead. The repository URL.                                                                                                                    |
| attributes   | repository_url               | string  | The repository URL. Accepts a full URL with or without a scheme (for example, `https://github.com/org/repo` or `github.com/org/repo`).                                                           |
| attributes   | service                      | string  | Filter coverage by service name. At most one of `service`, `codeowner`, or `flag` may be provided.                                                                                               |
| data         | type [*required*]       | enum    | JSON:API type for files coverage request. The value must always be `ci_app_coverage_files_request`. Allowed enum values: `ci_app_coverage_files_request`                                         |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "branch": "main",
      "changed_only": true,
      "codeowner": "@my-team",
      "commit_sha": "66adc9350f2cc9b250b69abddab733dd55e1a588",
      "flag": "unit-tests",
      "pr_number": 42,
      "repository_id": "github.com/datadog/shopist",
      "repository_url": "https://github.com/datadog/shopist",
      "service": "my-service"
    },
    "type": "ci_app_coverage_files_request"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Response object containing per-file code coverage data.

| Parent field         | Field            | Type      | Description                                                                                                                               |
| -------------------- | ---------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|                      | data             | object    | Data object for files coverage response.                                                                                                  |
| data                 | attributes       | object    | Attributes of the per-file code coverage response.                                                                                        |
| attributes           | base_commit_sha  | string    | The SHA of the base commit used for comparison (for example, the merge base for a PR).                                                    |
| attributes           | event_timestamp  | int64     | Unix timestamp (milliseconds) of the coverage event.                                                                                      |
| attributes           | files            | object    | Map of file paths to per-file coverage line data.                                                                                         |
| additionalProperties | <any-key>        | object    | Per-file line coverage data including executable, covered, and added lines.                                                               |
| <any-key>            | added_lines      | [integer] | Line numbers that were added in the specified scope (for example, in a PR diff).                                                          |
| <any-key>            | covered_lines    | [integer] | Line numbers that were covered by tests.                                                                                                  |
| <any-key>            | executable_lines | [integer] | Line numbers that are executable (can be covered).                                                                                        |
| attributes           | head_commit_sha  | string    | The SHA of the head commit for which coverage was evaluated.                                                                              |
| attributes           | report_count     | int64     | Number of coverage reports evaluated.                                                                                                     |
| data                 | id               | string    | Unique identifier for the files coverage response.                                                                                        |
| data                 | type             | enum      | JSON:API type for files coverage response. The value must always be `ci_app_coverage_files`. Allowed enum values: `ci_app_coverage_files` |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "base_commit_sha": "abc1234567890abcdef1234567890abcdef12345",
      "event_timestamp": 1709564000000,
      "files": {
        "<any-key>": {
          "added_lines": [
            11,
            12
          ],
          "covered_lines": [
            10,
            11,
            15
          ],
          "executable_lines": [
            10,
            11,
            12,
            15,
            20
          ]
        }
      },
      "head_commit_sha": "66adc9350f2cc9b250b69abddab733dd55e1a588",
      "report_count": 3
    },
    "id": "ZGQxMjM0NV9tYWluXzE3MDk1NjQwMDA=",
    "type": "ci_app_coverage_files"
  }
}
```

{% /tab %}

{% /tab %}

{% tab title="400" %}
Bad Request
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="403" %}
Not Authorized
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="404" %}
Not Found
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="429" %}
Too many requests
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

{% tab title="500" %}
Internal server error
{% tab title="Model" %}
API error response.

| Field                    | Type     | Description       |
| ------------------------ | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |

{% /tab %}

{% tab title="Example" %}

```json
{
  "errors": [
    "Bad Request"
  ]
}
```

{% /tab %}

{% /tab %}

### Code Example

##### 
                  \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/code-coverage/files" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "changed_only": true,
      "commit_sha": "66adc9350f2cc9b250b69abddab733dd55e1a588",
      "repository_url": "https://github.com/datadog/test-service"
    },
    "type": "ci_app_coverage_files_request"
  }
}
EOF 
                
{% /tab %}
