---
title: Compute a Sankey diagram
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > Product Analytics
---

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

# Compute a Sankey diagram{% #compute-a-sankey-diagram %}
Copy pageCopied
{% tab title="v2" %}
**Note**: This endpoint is in preview and is subject to change. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).
| Datadog site      | API endpoint                                                       |
| ----------------- | ------------------------------------------------------------------ |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/product-analytics/sankey |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/product-analytics/sankey |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/product-analytics/sankey      |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/product-analytics/sankey      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/product-analytics/sankey  |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/product-analytics/sankey |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/product-analytics/sankey     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/product-analytics/sankey |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/product-analytics/sankey |

### Overview

Compute a Sankey diagram of how sessions flow between the values of two facets, showing where users continue and where they drop off at each step. This endpoint requires the `rum_apps_read` permission.

### Request

#### Body Data (required)

The Sankey diagram query.

{% tab title="Model" %}

| Parent field     | Field                        | Type     | Description                                                                                                                                                                           |
| ---------------- | ---------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                  | data [*required*]       | object   | The single JSON:API resource carrying a Sankey query. Its attributes hold the time window to query, the search that selects the sessions, and the definition of the diagram to build. |
| data             | attributes [*required*] | object   | Attributes of a Sankey request.                                                                                                                                                       |
| attributes       | definition [*required*] | object   | The shape of the Sankey diagram, expressed as the facets to flow between and how many steps to show.                                                                                  |
| definition       | entries_per_step             | int64    | Maximum number of nodes to keep in each column. Remaining values are rolled up into an aggregated node. Omit it, or send `0`, to use the default of `5`.                              |
| definition       | number_of_steps              | int64    | Number of intermediate columns between the source and the target. Omit it, or send `0`, to use the default of `5`.                                                                    |
| definition       | source [*required*]     | string   | Facet forming the first column of the diagram.                                                                                                                                        |
| definition       | target [*required*]     | string   | Facet forming the last column of the diagram.                                                                                                                                         |
| attributes       | search [*required*]     | object   | Selects the sessions a Sankey diagram is built from.                                                                                                                                  |
| search           | audience_filters             | object   | Audience filter definitions for targeting specific user segments.                                                                                                                     |
| audience_filters | accounts                     | [object] | Account audience queries.                                                                                                                                                             |
| accounts         | name [*required*]       | string   | Name of this query, referenced in the formula.                                                                                                                                        |
| accounts         | query                        | string   | Search query for filtering accounts.                                                                                                                                                  |
| audience_filters | formula                      | string   | Boolean formula combining audience queries by name.                                                                                                                                   |
| audience_filters | segments                     | [object] | Segment audience queries.                                                                                                                                                             |
| segments         | name [*required*]       | string   | Name of this query, referenced in the formula.                                                                                                                                        |
| segments         | segment_id [*required*] | uuid     | UUID of the segment to filter by.                                                                                                                                                     |
| audience_filters | users                        | [object] | User audience queries.                                                                                                                                                                |
| users            | name [*required*]       | string   | Name of this query, referenced in the formula.                                                                                                                                        |
| users            | query                        | string   | Search query for filtering users.                                                                                                                                                     |
| search           | join_keys                    | object   | Identity join keys used to stitch events belonging to the same user or session.                                                                                                       |
| join_keys        | primary                      | string   | Primary identity join key. Defaults to `@session.id`.                                                                                                                                 |
| join_keys        | secondary                    | [string] | Additional identity join keys.                                                                                                                                                        |
| search           | query                        | string   | Datadog search query restricting the events considered.                                                                                                                               |
| attributes       | time [*required*]       | object   | The time window a Sankey query covers.                                                                                                                                                |
| time             | from [*required*]       | int64    | Start of the query window, in epoch milliseconds.                                                                                                                                     |
| time             | to [*required*]         | int64    | End of the query window, in epoch milliseconds.                                                                                                                                       |
| data             | type [*required*]       | enum     | The resource type identifier for a Sankey request. Allowed enum values: `sankey_request`                                                                                              |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "definition": {
        "entries_per_step": 10,
        "number_of_steps": 3,
        "source": "@view.name",
        "target": "@view.name"
      },
      "search": {
        "audience_filters": {
          "accounts": [
            {
              "name": "",
              "query": "string"
            }
          ],
          "formula": "u",
          "segments": [
            {
              "name": "",
              "segment_id": "00000000-0000-0000-0000-000000000000"
            }
          ],
          "users": [
            {
              "name": "u",
              "query": "*"
            }
          ]
        },
        "join_keys": {
          "primary": "@session.id",
          "secondary": []
        },
        "query": "@type:view"
      },
      "time": {
        "from": 1756425600000,
        "to": 1756857600000
      }
    },
    "type": "sankey_request"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Response for a Sankey diagram query.

| Parent field     | Field                        | Type     | Description                                                                                                                                                                                                                              |
| ---------------- | ---------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                  | data [*required*]       | object   | The single JSON:API resource holding a computed Sankey diagram. Its attributes contain the nodes of every column and the links that carry sessions between them.                                                                         |
| data             | attributes [*required*] | object   | Attributes of a Sankey response, containing the nodes and the links between them.                                                                                                                                                        |
| attributes       | links                        | [object] | The links of the diagram, one per pair of connected nodes.                                                                                                                                                                               |
| links            | column                       | int64    | Zero-based index of the column the link starts from.                                                                                                                                                                                     |
| links            | id                           | string   | Unique identifier for the link.                                                                                                                                                                                                          |
| links            | source                       | string   | Identifier of the node the link starts at.                                                                                                                                                                                               |
| links            | target                       | string   | Identifier of the node the link ends at.                                                                                                                                                                                                 |
| links            | value                        | int64    | Number of sessions flowing along the link.                                                                                                                                                                                               |
| attributes       | nodes                        | [object] | The nodes of the diagram, one per facet value and column.                                                                                                                                                                                |
| nodes            | aggregated_nodes             | [object] | The nodes rolled up into this one, when the node is an aggregate.                                                                                                                                                                        |
| aggregated_nodes | id                           | string   | Unique identifier for the node.                                                                                                                                                                                                          |
| aggregated_nodes | incoming_value               | int64    | Number of sessions entering the node.                                                                                                                                                                                                    |
| aggregated_nodes | name                         | string   | The facet value the node represents.                                                                                                                                                                                                     |
| aggregated_nodes | outgoing_value               | int64    | Number of sessions leaving the node.                                                                                                                                                                                                     |
| aggregated_nodes | type                         | enum     | The resource type identifier for a node rolled up into an aggregated node. Allowed enum values: `aggregated`                                                                                                                             |
| aggregated_nodes | value                        | int64    | Number of sessions passing through the node.                                                                                                                                                                                             |
| nodes            | column                       | int64    | Zero-based index of the column the node sits in.                                                                                                                                                                                         |
| nodes            | dropoff_value                | int64    | Number of sessions that ended at the node.                                                                                                                                                                                               |
| nodes            | id                           | string   | Unique identifier for the node.                                                                                                                                                                                                          |
| nodes            | incoming_value               | int64    | Number of sessions entering the node.                                                                                                                                                                                                    |
| nodes            | name                         | string   | The facet value the node represents.                                                                                                                                                                                                     |
| nodes            | outgoing_value               | int64    | Number of sessions leaving the node.                                                                                                                                                                                                     |
| nodes            | type                         | enum     | The kind of node. `regular` is a single facet value, `other` rolls up the values that did not fit within `entries_per_step`, and `dropoff` collects the sessions that ended at this column. Allowed enum values: `regular,other,dropoff` |
| nodes            | value                        | int64    | Number of sessions passing through the node.                                                                                                                                                                                             |
| data             | id [*required*]         | string   | Unique identifier for this response data object.                                                                                                                                                                                         |
| data             | type [*required*]       | enum     | The resource type identifier for a Sankey response. Allowed enum values: `sankey_response`                                                                                                                                               |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "links": [
        {
          "column": "integer",
          "id": "string",
          "source": "string",
          "target": "string",
          "value": "integer"
        }
      ],
      "nodes": [
        {
          "aggregated_nodes": [
            {
              "id": "string",
              "incoming_value": "integer",
              "name": "string",
              "outgoing_value": "integer",
              "type": "string",
              "value": "integer"
            }
          ],
          "column": "integer",
          "dropoff_value": "integer",
          "id": "string",
          "incoming_value": "integer",
          "name": "string",
          "outgoing_value": "integer",
          "type": "string",
          "value": "integer"
        }
      ]
    },
    "id": "00000000-0000-0000-0000-000000000000",
    "type": "sankey_response"
  }
}
```

{% /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="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 %}

### Code Example

##### 
                  \## default
# 
 \# Curl command curl -X POST "https://api.datadoghq.com/api/v2/product-analytics/sankey" \
-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": {
      "definition": {
        "entries_per_step": 10,
        "number_of_steps": 3,
        "source": "@view.name",
        "target": "@view.name"
      },
      "search": {
        "query": "@type:view"
      },
      "time": {
        "from": 1756425600000,
        "to": 1756857600000
      }
    },
    "type": "sankey_request"
  }
}
EOF 
                
##### 

```python
"""
Compute a Sankey diagram returns "OK" response
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.product_analytics_api import ProductAnalyticsApi
from datadog_api_client.v2.model.product_analytics_audience_account_subquery import (
    ProductAnalyticsAudienceAccountSubquery,
)
from datadog_api_client.v2.model.product_analytics_audience_filters import ProductAnalyticsAudienceFilters
from datadog_api_client.v2.model.product_analytics_audience_segment_subquery import (
    ProductAnalyticsAudienceSegmentSubquery,
)
from datadog_api_client.v2.model.product_analytics_audience_user_subquery import ProductAnalyticsAudienceUserSubquery
from datadog_api_client.v2.model.product_analytics_join_keys import ProductAnalyticsJoinKeys
from datadog_api_client.v2.model.product_analytics_sankey_definition import ProductAnalyticsSankeyDefinition
from datadog_api_client.v2.model.product_analytics_sankey_request import ProductAnalyticsSankeyRequest
from datadog_api_client.v2.model.product_analytics_sankey_request_attributes import (
    ProductAnalyticsSankeyRequestAttributes,
)
from datadog_api_client.v2.model.product_analytics_sankey_request_data import ProductAnalyticsSankeyRequestData
from datadog_api_client.v2.model.product_analytics_sankey_request_type import ProductAnalyticsSankeyRequestType
from datadog_api_client.v2.model.product_analytics_sankey_search import ProductAnalyticsSankeySearch
from datadog_api_client.v2.model.product_analytics_sankey_time import ProductAnalyticsSankeyTime
from uuid import UUID

body = ProductAnalyticsSankeyRequest(
    data=ProductAnalyticsSankeyRequestData(
        attributes=ProductAnalyticsSankeyRequestAttributes(
            definition=ProductAnalyticsSankeyDefinition(
                entries_per_step=10,
                number_of_steps=3,
                source="@view.name",
                target="@view.name",
            ),
            search=ProductAnalyticsSankeySearch(
                audience_filters=ProductAnalyticsAudienceFilters(
                    accounts=[
                        ProductAnalyticsAudienceAccountSubquery(
                            name="",
                        ),
                    ],
                    formula="u",
                    segments=[
                        ProductAnalyticsAudienceSegmentSubquery(
                            name="",
                            segment_id=UUID("00000000-0000-0000-0000-000000000000"),
                        ),
                    ],
                    users=[
                        ProductAnalyticsAudienceUserSubquery(
                            name="u",
                            query="*",
                        ),
                    ],
                ),
                join_keys=ProductAnalyticsJoinKeys(
                    primary="@session.id",
                    secondary=[],
                ),
                query="@type:view",
            ),
            time=ProductAnalyticsSankeyTime(
                _from=1756425600000,
                to=1756857600000,
            ),
        ),
        type=ProductAnalyticsSankeyRequestType.SANKEY_REQUEST,
    ),
)

configuration = Configuration()
configuration.unstable_operations["query_product_analytics_sankey"] = True
with ApiClient(configuration) as api_client:
    api_instance = ProductAnalyticsApi(api_client)
    response = api_instance.query_product_analytics_sankey(body=body)

    print(response)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=python) and then save the example to `example.py` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" python3 "example.py"
##### 

```ruby
# Compute a Sankey diagram returns "OK" response

require "datadog_api_client"
DatadogAPIClient.configure do |config|
  config.unstable_operations["v2.query_product_analytics_sankey".to_sym] = true
end
api_instance = DatadogAPIClient::V2::ProductAnalyticsAPI.new

body = DatadogAPIClient::V2::ProductAnalyticsSankeyRequest.new({
  data: DatadogAPIClient::V2::ProductAnalyticsSankeyRequestData.new({
    attributes: DatadogAPIClient::V2::ProductAnalyticsSankeyRequestAttributes.new({
      definition: DatadogAPIClient::V2::ProductAnalyticsSankeyDefinition.new({
        entries_per_step: 10,
        number_of_steps: 3,
        source: "@view.name",
        target: "@view.name",
      }),
      search: DatadogAPIClient::V2::ProductAnalyticsSankeySearch.new({
        audience_filters: DatadogAPIClient::V2::ProductAnalyticsAudienceFilters.new({
          accounts: [
            DatadogAPIClient::V2::ProductAnalyticsAudienceAccountSubquery.new({
              name: "",
            }),
          ],
          formula: "u",
          segments: [
            DatadogAPIClient::V2::ProductAnalyticsAudienceSegmentSubquery.new({
              name: "",
              segment_id: "00000000-0000-0000-0000-000000000000",
            }),
          ],
          users: [
            DatadogAPIClient::V2::ProductAnalyticsAudienceUserSubquery.new({
              name: "u",
              query: "*",
            }),
          ],
        }),
        join_keys: DatadogAPIClient::V2::ProductAnalyticsJoinKeys.new({
          primary: "@session.id",
          secondary: [],
        }),
        query: "@type:view",
      }),
      time: DatadogAPIClient::V2::ProductAnalyticsSankeyTime.new({
        from: 1756425600000,
        to: 1756857600000,
      }),
    }),
    type: DatadogAPIClient::V2::ProductAnalyticsSankeyRequestType::SANKEY_REQUEST,
  }),
})
p api_instance.query_product_analytics_sankey(body)
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=ruby) and then save the example to `example.rb` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" rb "example.rb"
##### 

```go
// Compute a Sankey diagram 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"
	"github.com/google/uuid"
)

func main() {
	body := datadogV2.ProductAnalyticsSankeyRequest{
		Data: datadogV2.ProductAnalyticsSankeyRequestData{
			Attributes: datadogV2.ProductAnalyticsSankeyRequestAttributes{
				Definition: datadogV2.ProductAnalyticsSankeyDefinition{
					EntriesPerStep: datadog.PtrInt64(10),
					NumberOfSteps:  datadog.PtrInt64(3),
					Source:         "@view.name",
					Target:         "@view.name",
				},
				Search: datadogV2.ProductAnalyticsSankeySearch{
					AudienceFilters: &datadogV2.ProductAnalyticsAudienceFilters{
						Accounts: []datadogV2.ProductAnalyticsAudienceAccountSubquery{
							{
								Name: "",
							},
						},
						Formula: datadog.PtrString("u"),
						Segments: []datadogV2.ProductAnalyticsAudienceSegmentSubquery{
							{
								Name:      "",
								SegmentId: uuid.MustParse("00000000-0000-0000-0000-000000000000"),
							},
						},
						Users: []datadogV2.ProductAnalyticsAudienceUserSubquery{
							{
								Name:  "u",
								Query: datadog.PtrString("*"),
							},
						},
					},
					JoinKeys: &datadogV2.ProductAnalyticsJoinKeys{
						Primary:   datadog.PtrString("@session.id"),
						Secondary: []string{},
					},
					Query: datadog.PtrString("@type:view"),
				},
				Time: datadogV2.ProductAnalyticsSankeyTime{
					From: 1756425600000,
					To:   1756857600000,
				},
			},
			Type: datadogV2.PRODUCTANALYTICSSANKEYREQUESTTYPE_SANKEY_REQUEST,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	configuration.SetUnstableOperationEnabled("v2.QueryProductAnalyticsSankey", true)
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewProductAnalyticsApi(apiClient)
	resp, r, err := api.QueryProductAnalyticsSankey(ctx, body)

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

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

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=go) and then save the example to `main.go` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" go run "main.go"
##### 

```java
// Compute a Sankey diagram returns "OK" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.ProductAnalyticsApi;
import com.datadog.api.client.v2.model.ProductAnalyticsAudienceAccountSubquery;
import com.datadog.api.client.v2.model.ProductAnalyticsAudienceFilters;
import com.datadog.api.client.v2.model.ProductAnalyticsAudienceSegmentSubquery;
import com.datadog.api.client.v2.model.ProductAnalyticsAudienceUserSubquery;
import com.datadog.api.client.v2.model.ProductAnalyticsJoinKeys;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeyDefinition;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeyRequest;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeyRequestAttributes;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeyRequestData;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeyRequestType;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeyResponse;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeySearch;
import com.datadog.api.client.v2.model.ProductAnalyticsSankeyTime;
import java.util.Collections;
import java.util.UUID;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    defaultClient.setUnstableOperationEnabled("v2.queryProductAnalyticsSankey", true);
    ProductAnalyticsApi apiInstance = new ProductAnalyticsApi(defaultClient);

    ProductAnalyticsSankeyRequest body =
        new ProductAnalyticsSankeyRequest()
            .data(
                new ProductAnalyticsSankeyRequestData()
                    .attributes(
                        new ProductAnalyticsSankeyRequestAttributes()
                            .definition(
                                new ProductAnalyticsSankeyDefinition()
                                    .entriesPerStep(10L)
                                    .numberOfSteps(3L)
                                    .source("@view.name")
                                    .target("@view.name"))
                            .search(
                                new ProductAnalyticsSankeySearch()
                                    .audienceFilters(
                                        new ProductAnalyticsAudienceFilters()
                                            .accounts(
                                                Collections.singletonList(
                                                    new ProductAnalyticsAudienceAccountSubquery()
                                                        .name("")))
                                            .formula("u")
                                            .segments(
                                                Collections.singletonList(
                                                    new ProductAnalyticsAudienceSegmentSubquery()
                                                        .name("")
                                                        .segmentId(
                                                            UUID.fromString(
                                                                "00000000-0000-0000-0000-000000000000"))))
                                            .users(
                                                Collections.singletonList(
                                                    new ProductAnalyticsAudienceUserSubquery()
                                                        .name("u")
                                                        .query("*"))))
                                    .joinKeys(new ProductAnalyticsJoinKeys().primary("@session.id"))
                                    .query("@type:view"))
                            .time(
                                new ProductAnalyticsSankeyTime()
                                    .from(1756425600000L)
                                    .to(1756857600000L)))
                    .type(ProductAnalyticsSankeyRequestType.SANKEY_REQUEST));

    try {
      ProductAnalyticsSankeyResponse result = apiInstance.queryProductAnalyticsSankey(body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling ProductAnalyticsApi#queryProductAnalyticsSankey");
      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://docs.datadoghq.com/api/latest.md?code-lang=java) and then save the example to `Example.java` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" java "Example.java"
##### 

```rust
// Compute a Sankey diagram returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_product_analytics::ProductAnalyticsAPI;
use datadog_api_client::datadogV2::model::ProductAnalyticsAudienceAccountSubquery;
use datadog_api_client::datadogV2::model::ProductAnalyticsAudienceFilters;
use datadog_api_client::datadogV2::model::ProductAnalyticsAudienceSegmentSubquery;
use datadog_api_client::datadogV2::model::ProductAnalyticsAudienceUserSubquery;
use datadog_api_client::datadogV2::model::ProductAnalyticsJoinKeys;
use datadog_api_client::datadogV2::model::ProductAnalyticsSankeyDefinition;
use datadog_api_client::datadogV2::model::ProductAnalyticsSankeyRequest;
use datadog_api_client::datadogV2::model::ProductAnalyticsSankeyRequestAttributes;
use datadog_api_client::datadogV2::model::ProductAnalyticsSankeyRequestData;
use datadog_api_client::datadogV2::model::ProductAnalyticsSankeyRequestType;
use datadog_api_client::datadogV2::model::ProductAnalyticsSankeySearch;
use datadog_api_client::datadogV2::model::ProductAnalyticsSankeyTime;
use uuid::Uuid;

#[tokio::main]
async fn main() {
    let body = ProductAnalyticsSankeyRequest::new(ProductAnalyticsSankeyRequestData::new(
        ProductAnalyticsSankeyRequestAttributes::new(
            ProductAnalyticsSankeyDefinition::new(
                "@view.name".to_string(),
                "@view.name".to_string(),
            )
            .entries_per_step(10)
            .number_of_steps(3),
            ProductAnalyticsSankeySearch::new()
                .audience_filters(
                    ProductAnalyticsAudienceFilters::new()
                        .accounts(vec![ProductAnalyticsAudienceAccountSubquery::new(
                            "".to_string(),
                        )])
                        .formula("u".to_string())
                        .segments(vec![ProductAnalyticsAudienceSegmentSubquery::new(
                            "".to_string(),
                            Uuid::parse_str("00000000-0000-0000-0000-000000000000")
                                .expect("invalid UUID"),
                        )])
                        .users(vec![ProductAnalyticsAudienceUserSubquery::new(
                            "u".to_string(),
                        )
                        .query("*".to_string())]),
                )
                .join_keys(
                    ProductAnalyticsJoinKeys::new()
                        .primary("@session.id".to_string())
                        .secondary(vec![]),
                )
                .query("@type:view".to_string()),
            ProductAnalyticsSankeyTime::new(1756425600000, 1756857600000),
        ),
        ProductAnalyticsSankeyRequestType::SANKEY_REQUEST,
    ));
    let mut configuration = datadog::Configuration::new();
    configuration.set_unstable_operation_enabled("v2.QueryProductAnalyticsSankey", true);
    let api = ProductAnalyticsAPI::with_config(configuration);
    let resp = api.query_product_analytics_sankey(body).await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}
```

#### Instructions

First [install the library and its dependencies](https://docs.datadoghq.com/api/latest.md?code-lang=rust) and then save the example to `src/main.rs` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" cargo run
##### 

```typescript
/**
 * Compute a Sankey diagram returns "OK" response
 */

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

const configuration = client.createConfiguration();
configuration.unstableOperations["v2.queryProductAnalyticsSankey"] = true;
const apiInstance = new v2.ProductAnalyticsApi(configuration);

const params: v2.ProductAnalyticsApiQueryProductAnalyticsSankeyRequest = {
  body: {
    data: {
      attributes: {
        definition: {
          entriesPerStep: 10,
          numberOfSteps: 3,
          source: "@view.name",
          target: "@view.name",
        },
        search: {
          audienceFilters: {
            accounts: [
              {
                name: "",
              },
            ],
            formula: "u",
            segments: [
              {
                name: "",
                segmentId: "00000000-0000-0000-0000-000000000000",
              },
            ],
            users: [
              {
                name: "u",
                query: "*",
              },
            ],
          },
          joinKeys: {
            primary: "@session.id",
            secondary: [],
          },
          query: "@type:view",
        },
        time: {
          from: 1756425600000,
          to: 1756857600000,
        },
      },
      type: "sankey_request",
    },
  },
};

apiInstance
  .queryProductAnalyticsSankey(params)
  .then((data: v2.ProductAnalyticsSankeyResponse) => {
    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://docs.datadoghq.com/api/latest.md?code-lang=typescript) and then save the example to `example.ts` and run following commands:
    DD_SITE="datadoghq.com" DD_API_KEY="<API-KEY>" DD_APP_KEY="<APP-KEY>" tsc "example.ts"
{% /tab %}
