---
title: "Get per-file code coverage data"
method: POST
path: "/api/v2/code-coverage/files"
tags: ["Code Coverage"]
---

# Get per-file code coverage data

`POST /api/v2/code-coverage/files`

## Request

- Base URL: `https://api.datadoghq.com`
- URL: `https://api.datadoghq.com/api/v2/code-coverage/files`
- Auth: one of:
  - API key in header `DD-API-KEY` and API key in header `DD-APPLICATION-KEY`
  - OAuth 2
    - Authorization code: `/oauth2/v1/authorize`
    - Token URL: `/oauth2/v1/token` scopes: `code_coverage_read`
- TypeScript: <https://skmtc.dev/datadog/apis/datadog-api-v2-collection/docs/api/v2/code-coverage/files/post.ts> (a function with typed inputs; its response is checked against the schema)

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

## Request body

- FilesCoverageRequest: Request object for getting per-file code coverage data.
  - `data` FilesCoverageRequestData, required: Data object for files coverage request.
    - `attributes` FilesCoverageRequestAttributes, required: 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.
      - `branch` string: The branch name.
      - `changed_only` boolean: When true, return coverage data only for files that were changed in the specified scope.
      - `codeowner` string: Filter coverage by code owner. At most one of `service`, `codeowner`, or `flag` may be provided.
      - `commit_sha` string: The commit SHA (40-character hexadecimal string).
      - `flag` string: Filter coverage by coverage flag. At most one of `service`, `codeowner`, or `flag` may be provided.
      - `pr_number` integer: The pull request number. Must be a positive integer.
      - `repository_id` string: Deprecated: use `repository_url` instead. The repository URL.
      - `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`).
      - `service` string: Filter coverage by service name. At most one of `service`, `codeowner`, or `flag` may be provided.
    - `type` 'ci_app_coverage_files_request', required: JSON:API type for files coverage request. The value must always be `ci_app_coverage_files_request`.

## Response `200`

OK

- FilesCoverageResponse: Response object containing per-file code coverage data.
  - `data` FilesCoverageData: Data object for files coverage response.
    - `attributes` FilesCoverageAttributes: Attributes of the per-file code coverage response.
      - `base_commit_sha` string: The SHA of the base commit used for comparison (for example, the merge base for a PR).
      - `event_timestamp` integer: Unix timestamp (milliseconds) of the coverage event.
      - `files` object: Map of file paths to per-file coverage line data.
      - `head_commit_sha` string: The SHA of the head commit for which coverage was evaluated.
      - `report_count` integer: Number of coverage reports evaluated.
    - `id` string: Unique identifier for the files coverage response.
    - `type` 'ci_app_coverage_files': JSON:API type for files coverage response. The value must always be `ci_app_coverage_files`.

## Other responses

- `400`: Bad Request
- `403`: Not Authorized
- `404`: Not Found
- `429`: Too many requests
- `500`: Internal server error

---

[API](https://skmtc.dev/datadog/apis/datadog-api-v2-collection.md) - [All operations](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/llms.txt) - [OpenAPI document](https://skmtc.dev/datadog/apis/datadog-api-v2-collection/revisions/3f70db624329?raw)
