---
title: Récupérer le résumé de couverture de code pour une branche
description: Récupérer des statistiques agrégées de couverture de code pour une branche spécifique dans un référentiel.
breadcrumbs: Documentation > API > Récupérer le résumé de couverture de code pour une branche
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/llms.txt).

# Récupérer le résumé de couverture de code pour une branche

## v2 (latest)

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

### Overview

Récupérer des statistiques agrégées de couverture de code pour une branche spécifique dans un référentiel.
Cet endpoint fournit des métriques de couverture globales ainsi que des ventilations par service
et par propriétaire de code.

This endpoint requires the `code_coverage_read` permission.

OAuth apps require the `code_coverage_read` authorization [scope](https://dnd37xeb23o8n.cloudfront.net/stefon.simmons/docs-astro-web-10435/fr/api/latest/scopes.md#code-coverage) to access this endpoint.

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field | Field                   | Type   | Description                                                                                                                                                                          |
| ------------ | ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|              | data [*required*]       | object | Objet de requête pour la récupération du résumé de couverture de code pour une branche.                                                                                              |
| data         | attributes [*required*] | object | Attributes for requesting code coverage summary for a branch.                                                                                                                        |
| attributes   | branch [*required*]     | string | The branch name.                                                                                                                                                                     |
| 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`).                                               |
| data         | type [*required*]       | enum   | JSON:API type for branch coverage summary request. The value must always be `ci_app_coverage_branch_summary_request`. Allowed enum values: `ci_app_coverage_branch_summary_request`. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "branch": "prod",
      "repository_id": "github.com/datadog/shopist",
      "repository_url": "https://github.com/datadog/shopist"
    },
    "type": "ci_app_coverage_branch_summary_request"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="200" %}
OK

{% tabs %}
{% tab label="Model" %}
Response object containing code coverage summary.

| Parent field         | Field                   | Type   | Description                                                                                                                                      |
| -------------------- | ----------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|                      | data                    | object | Data object for coverage summary response.                                                                                                       |
| data                 | attributes              | object | Attributes object for code coverage summary response.                                                                                            |
| attributes           | codeowners              | object | Coverage statistics broken down by code owner.                                                                                                   |
| additionalProperties | <any-key>               | object | Coverage statistics for a specific code owner.                                                                                                   |
| <any-key>            | evaluated_flags_count   | int64  | Number of coverage flags evaluated for the code owner.                                                                                           |
| <any-key>            | evaluated_reports_count | int64  | Number of coverage reports evaluated for the code owner.                                                                                         |
| <any-key>            | patch_coverage          | double | Patch coverage percentage for the code owner.                                                                                                    |
| <any-key>            | total_coverage          | double | Total coverage percentage for the code owner.                                                                                                    |
| attributes           | evaluated_flags_count   | int64  | Total number of coverage flags evaluated.                                                                                                        |
| attributes           | evaluated_reports_count | int64  | Total number of coverage reports evaluated.                                                                                                      |
| attributes           | patch_coverage          | double | Overall patch coverage percentage.                                                                                                               |
| attributes           | services                | object | Coverage statistics broken down by service.                                                                                                      |
| additionalProperties | <any-key>               | object | Coverage statistics for a specific service.                                                                                                      |
| <any-key>            | evaluated_flags_count   | int64  | Number of coverage flags evaluated for the service.                                                                                              |
| <any-key>            | evaluated_reports_count | int64  | Number of coverage reports evaluated for the service.                                                                                            |
| <any-key>            | patch_coverage          | double | Patch coverage percentage for the service.                                                                                                       |
| <any-key>            | total_coverage          | double | Total coverage percentage for the service.                                                                                                       |
| attributes           | total_coverage          | double | Overall total coverage percentage.                                                                                                               |
| data                 | id                      | string | Unique identifier for the coverage summary (base64-hashed).                                                                                      |
| data                 | type                    | enum   | JSON:API type for coverage summary response. The value must always be `ci_app_coverage_summary`. Allowed enum values: `ci_app_coverage_summary`. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "codeowners": {
        "<any-key>": {
          "evaluated_flags_count": 2,
          "evaluated_reports_count": 4,
          "patch_coverage": 75.2,
          "total_coverage": 88.7
        }
      },
      "evaluated_flags_count": 8,
      "evaluated_reports_count": 12,
      "patch_coverage": 70.1,
      "services": {
        "<any-key>": {
          "evaluated_flags_count": 3,
          "evaluated_reports_count": 5,
          "patch_coverage": 72.3,
          "total_coverage": 85.5
        }
      },
      "total_coverage": 82.4
    },
    "id": "ZGQxMjM0NV9tYWluXzE3MDk1NjQwMDA=",
    "type": "ci_app_coverage_summary"
  }
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="400" %}
Bad Request

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="403" %}
Not Authorized

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="404" %}
Not Found

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too many requests

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="500" %}
Internal server error

{% tabs %}
{% tab label="Model" %}
API error response.

| Field               | Type     | Description       |
| ------------------- | -------- | ----------------- |
| errors [*required*] | [string] | A list of errors. |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    "Bad Request"
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
# Set your Datadog site and credentials
export DD_SITE="datadoghq.com" # Or us3.datadoghq.com, us5.datadoghq.com, datadoghq.eu, ap1.datadoghq.com, ap2.datadoghq.com, uk1.datadoghq.com, ddog-gov.com, us2.ddog-gov.com
# Use a Personal Access Token or Service Access Token
export DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"

curl -X POST "https://api.${DD_SITE}/api/v2/code-coverage/branch/summary" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "branch": "prod",
      "repository_url": "https://github.com/datadog/test-service"
    },
    "type": "ci_app_coverage_branch_summary_request"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Get code coverage summary for a branch returns "OK" response

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"

	"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
	"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
	body := datadogV2.BranchCoverageSummaryRequest{
		Data: datadogV2.BranchCoverageSummaryRequestData{
			Attributes: datadogV2.BranchCoverageSummaryRequestAttributes{
				Branch:        "prod",
				RepositoryId:  datadog.PtrString("github.com/datadog/shopist"),
				RepositoryUrl: datadog.PtrString("https://github.com/datadog/shopist"),
			},
			Type: datadogV2.BRANCHCOVERAGESUMMARYREQUESTTYPE_CI_APP_COVERAGE_BRANCH_SUMMARY_REQUEST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	ctx = context.WithValue(ctx, datadog.ContextAccessToken, os.Getenv("DD_BEARER_TOKEN"))
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewCodeCoverageApi(apiClient)
	resp, r, err := api.GetCodeCoverageBranchSummary(ctx, body)

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `CodeCoverageApi.GetCodeCoverageBranchSummary`: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `CodeCoverageApi.GetCodeCoverageBranchSummary`:\n%s\n", responseContent)
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" go run "main.go"
```
{% /tab %}

{% tab label="Java" %}
```java
// Get code coverage summary for a branch returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.CodeCoverageApi;
import com.datadog.api.client.v2.model.BranchCoverageSummaryRequest;
import com.datadog.api.client.v2.model.BranchCoverageSummaryRequestAttributes;
import com.datadog.api.client.v2.model.BranchCoverageSummaryRequestData;
import com.datadog.api.client.v2.model.BranchCoverageSummaryRequestType;
import com.datadog.api.client.v2.model.CoverageSummaryResponse;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));
    CodeCoverageApi apiInstance = new CodeCoverageApi(defaultClient);

    BranchCoverageSummaryRequest body =
        new BranchCoverageSummaryRequest()
            .data(
                new BranchCoverageSummaryRequestData()
                    .attributes(
                        new BranchCoverageSummaryRequestAttributes()
                            .branch("prod")
                            .repositoryId("github.com/datadog/shopist")
                            .repositoryUrl("https://github.com/datadog/shopist"))
                    .type(BranchCoverageSummaryRequestType.CI_APP_COVERAGE_BRANCH_SUMMARY_REQUEST));

    try {
      CoverageSummaryResponse result = apiInstance.getCodeCoverageBranchSummary(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling CodeCoverageApi#getCodeCoverageBranchSummary");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" java "Example.java"
```
{% /tab %}

{% tab label="Python" %}
```python
"""
Get code coverage summary for a branch returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.code_coverage_api import CodeCoverageApi
from datadog_api_client.v2.model.branch_coverage_summary_request import BranchCoverageSummaryRequest
from datadog_api_client.v2.model.branch_coverage_summary_request_attributes import (
    BranchCoverageSummaryRequestAttributes,
)
from datadog_api_client.v2.model.branch_coverage_summary_request_data import BranchCoverageSummaryRequestData
from datadog_api_client.v2.model.branch_coverage_summary_request_type import BranchCoverageSummaryRequestType

body = BranchCoverageSummaryRequest(
    data=BranchCoverageSummaryRequestData(
        attributes=BranchCoverageSummaryRequestAttributes(
            branch="prod",
            repository_id="github.com/datadog/shopist",
            repository_url="https://github.com/datadog/shopist",
        ),
        type=BranchCoverageSummaryRequestType.CI_APP_COVERAGE_BRANCH_SUMMARY_REQUEST,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
    api_instance = CodeCoverageApi(api_client)
    response = api_instance.get_code_coverage_branch_summary(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" python3 "example.py"
```
{% /tab %}

{% tab label="Ruby" %}
```ruby
# Get code coverage summary for a branch returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.access_token = ENV["DD_BEARER_TOKEN"]
end
api_instance = DatadogAPIClient::V2::CodeCoverageAPI.new

body = DatadogAPIClient::V2::BranchCoverageSummaryRequest.new({
  data: DatadogAPIClient::V2::BranchCoverageSummaryRequestData.new({
    attributes: DatadogAPIClient::V2::BranchCoverageSummaryRequestAttributes.new({
      branch: "prod",
      repository_id: "github.com/datadog/shopist",
      repository_url: "https://github.com/datadog/shopist",
    }),
    type: DatadogAPIClient::V2::BranchCoverageSummaryRequestType::CI_APP_COVERAGE_BRANCH_SUMMARY_REQUEST,
  }),
})
p api_instance.get_code_coverage_branch_summary(body)
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" rb "example.rb"
```
{% /tab %}

{% tab label="Rust" %}
```rust
// Get code coverage summary for a branch returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_code_coverage::CodeCoverageAPI;
use datadog_api_client::datadogV2::model::BranchCoverageSummaryRequest;
use datadog_api_client::datadogV2::model::BranchCoverageSummaryRequestAttributes;
use datadog_api_client::datadogV2::model::BranchCoverageSummaryRequestData;
use datadog_api_client::datadogV2::model::BranchCoverageSummaryRequestType;

#[tokio::main]
async fn main() {
    let body = BranchCoverageSummaryRequest::new(BranchCoverageSummaryRequestData::new(
        BranchCoverageSummaryRequestAttributes::new("prod".to_string())
            .repository_id("github.com/datadog/shopist".to_string())
            .repository_url("https://github.com/datadog/shopist".to_string()),
        BranchCoverageSummaryRequestType::CI_APP_COVERAGE_BRANCH_SUMMARY_REQUEST,
    ));
    let configuration = datadog::Configuration::new();
    let api = CodeCoverageAPI::with_config(configuration);
    let resp = api.get_code_coverage_branch_summary(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_API_KEY="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
```
{% /tab %}

{% tab label="TypeScript" %}
```typescript
/**
 * Get code coverage summary for a branch returns "OK" response
 */

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration({
  authMethods: {
    AuthZ: {
      accessToken: process.env.DD_BEARER_TOKEN as string,
    },
  },
});
const apiInstance = new v2.CodeCoverageApi(configuration);

const params: v2.CodeCoverageApiGetCodeCoverageBranchSummaryRequest = {
  body: {
    data: {
      attributes: {
        branch: "prod",
        repositoryId: "github.com/datadog/shopist",
        repositoryUrl: "https://github.com/datadog/shopist",
      },
      type: "ci_app_coverage_branch_summary_request",
    },
  },
};

apiInstance
  .getCodeCoverageBranchSummary(params)
  .then((data: v2.CoverageSummaryResponse) => {
    console.log(
      "API called successfully. Returned data: " + JSON.stringify(data)
    );
  })
  .catch((error: any) => console.error(error));
```

#### Instructions

First [install the library and its dependencies](https://dnd37xeb23o8n.cloudfront.net/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:

```bash
DD_SITE="datadoghq.com" DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>" tsc "example.ts"
```
{% /tab %}
{% /tabs %}
