---
title: Envoyer des événements côté serveur
description: Envoyer des événements côté serveur à Product Analytics.
breadcrumbs: Documentation > API > Envoyer des événements côté serveur
---

> For the complete documentation index, see [llms.txt](https://dnd37xeb23o8n.cloudfront.net/jen.gilbert/astro-base/llms.txt).

# Envoyer des événements côté serveur

## v2 (latest)

| Datadog site      | API endpoint                                                    |
| ----------------- | --------------------------------------------------------------- |
| app.datadoghq.com | POST https://browser-intake-datadoghq.com/api/v2/prodlytics     |
| us3.datadoghq.com | POST https://browser-intake-us3-datadoghq.com/api/v2/prodlytics |
| us5.datadoghq.com | POST https://browser-intake-us5-datadoghq.com/api/v2/prodlytics |
| app.datadoghq.eu  | POST https://browser-intake-datadoghq.eu/api/v2/prodlytics      |
| ap1.datadoghq.com | POST https://browser-intake-ap1-datadoghq.com/api/v2/prodlytics |
| ap2.datadoghq.com | POST https://browser-intake-ap2-datadoghq.com/api/v2/prodlytics |
| uk1.datadoghq.com | POST https://browser-intake-uk1-datadoghq.com/api/v2/prodlytics |
| app.ddog-gov.com  | POST Not supported in the US1-FED region                        |
| us2.ddog-gov.com  | POST Not supported in the US2-FED region                        |

### Overview

Envoyer des événements côté serveur à Product Analytics. Les événements côté serveur sont conservés pendant 15 mois.

Les événements côté serveur dans Product Analytics sont utiles pour suivre les événements qui se produisent sur le serveur,
par opposition aux événements côté client, qui sont capturés par les SDK Real User Monitoring (RUM).
Cela permet d'obtenir une vue plus complète du parcours utilisateur en incluant les actions qui se produisent sur le serveur.
Des exemples typiques pourraient être `checkout.completed` ou `payment.processed`.

Les événements côté serveur ingérés sont intégrés dans Product Analytics pour permettre aux utilisateurs de sélectionner et de filtrer
ces événements dans le sélecteur d'événements, de la même manière que les vues ou les actions sont gérées.

**Prérequis :**

- Au moins l'un des champs `usr`, `account` ou `session` doit être fourni avec un ID valide.
- L'`application.id` doit référencer une application avec Product Analytics activé.

**Attributs personnalisés :**
Tous les champs supplémentaires de la charge utile sont aplatis et consultables en tant que facettes.
Par exemple, une charge utile contenant `{"customer": {"tier": "premium"}}` est consultable avec
la syntaxe `@customer.tier:premium` dans Datadog.

Les codes de statut renvoyés par l'API HTTP sont :

- 202 : accepté : la requête a été acceptée pour traitement
- 400 : requête incorrecte (probablement un problème de formatage de la charge utile)
- 401 : non autorisé (probablement une clé API manquante)
- 403 : problème d'autorisation (probablement une clé API invalide)
- 408 : délai d'attente de la requête, la requête doit être retentée après un certain délai
- 413 : charge utile trop volumineuse (le lot dépasse 5 Mo non compressé)
- 429 : trop de requêtes, la requête doit être retentée après un certain délai
- 500 : erreur interne du serveur, le serveur a rencontré une condition inattendue l'empêchant de traiter la requête, celle-ci doit être retentée après un certain délai
- 503 : service indisponible, le serveur n'est pas en mesure de traiter la requête, probablement en raison d'une surcharge, la requête doit être retentée après un certain délai.

### Request

#### Body Data (required)

Événement côté serveur à envoyer (format JSON).

{% tabs %}
{% tab label="Model" %}
| Parent field | Field                    | Type   | Description                                                                                                                        |
| ------------ | ------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------- |
|              | account                  | object | Un événement Product Analytics côté serveur.                                                                                       |
| account      | id [*required*]          | string | The account ID used in Datadog.                                                                                                    |
|              | application [*required*] | object | The application in which you want to send your events.                                                                             |
| application  | id [*required*]          | string | The application ID of your application. It can be found in your [application management page](https://app.datadoghq.com/rum/list). |
|              | event [*required*]       | object | Fields used for the event.                                                                                                         |
| event        | name [*required*]        | string | The name of your event, which is used for search in the same way as view or action names.                                          |
|              | session                  | object | The session linked to your event.                                                                                                  |
| session      | id [*required*]          | string | The session ID captured by the SDK.                                                                                                |
|              | type [*required*]        | enum   | The type of Product Analytics event. Must be `server` for server-side events. Allowed enum values: `server`.                       |
|              | usr                      | object | The user linked to your event.                                                                                                     |
| usr          | id [*required*]          | string | The user ID used in Datadog.                                                                                                       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "account": {
    "id": "account-67890"
  },
  "application": {
    "id": "123abcde-123a-123b-1234-123456789abc"
  },
  "event": {
    "name": "payment.processed"
  },
  "session": {
    "id": "session-abcdef"
  },
  "type": "server",
  "usr": {
    "id": "user-12345"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="202" %}
Request accepted for processing (always 202 empty JSON).

{% tabs %}
{% tab label="Model" %}
| Field | Type | Description |
| ----- | ---- | ----------- |
{% /tab %}

{% tab label="Example" %}
```json
{}
```
{% /tab %}
{% /tabs %}
{% /tab %}

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

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="401" %}
Unauthorized

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="403" %}
Forbidden

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="408" %}
Request Timeout

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="413" %}
Payload Too Large

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="429" %}
Too Many Requests

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="500" %}
Internal Server Error

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}

{% tab label="503" %}
Service Unavailable

{% tabs %}
{% tab label="Model" %}
Error response.

| Parent field | Field  | Type     | Description        |
| ------------ | ------ | -------- | ------------------ |
|              | errors | [object] | Structured errors. |
| errors       | detail | string   | Error message.     |
| errors       | status | string   | Error code.        |
| errors       | title  | string   | Error title.       |
{% /tab %}

{% tab label="Example" %}
```json
{
  "errors": [
    {
      "detail": "Malformed payload",
      "status": "400",
      "title": "Bad Request"
    }
  ]
}
```
{% /tab %}
{% /tabs %}
{% /tab %}
{% /tabs %}

### Code Example

{% tabs %}
{% tab label="Curl" %}
```bash
## default

# Set your Datadog credentials
export DD_API_KEY="<DD_API_KEY>"

# For sites other than datadoghq.com, replace the host below with: browser-intake-us3-datadoghq.com (us3.datadoghq.com), browser-intake-us5-datadoghq.com (us5.datadoghq.com), browser-intake-datadoghq.eu (datadoghq.eu), browser-intake-ap1-datadoghq.com (ap1.datadoghq.com), browser-intake-ap2-datadoghq.com (ap2.datadoghq.com), browser-intake-uk1-datadoghq.com (uk1.datadoghq.com)
curl -X POST "https://browser-intake-datadoghq.com/api/v2/prodlytics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-d @- << EOF
{
  "application": {
    "id": "123abcde-123a-123b-1234-123456789abc"
  },
  "event": {
    "name": "payment.processed"
  },
  "type": "server",
  "usr": {
    "id": "123"
  }
}
EOF

## Event with account ID
# Send a server-side event linked to an account.

# Set your Datadog credentials
export DD_API_KEY="<DD_API_KEY>"

# For sites other than datadoghq.com, replace the host below with: browser-intake-us3-datadoghq.com (us3.datadoghq.com), browser-intake-us5-datadoghq.com (us5.datadoghq.com), browser-intake-datadoghq.eu (datadoghq.eu), browser-intake-ap1-datadoghq.com (ap1.datadoghq.com), browser-intake-ap2-datadoghq.com (ap2.datadoghq.com), browser-intake-uk1-datadoghq.com (uk1.datadoghq.com)
curl -X POST "https://browser-intake-datadoghq.com/api/v2/prodlytics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-d @- << EOF
{
  "account": {
    "id": "account-456"
  },
  "application": {
    "id": "123abcde-123a-123b-1234-123456789abc"
  },
  "event": {
    "name": "checkout.completed"
  },
  "type": "server"
}
EOF

## Event with custom attributes
# Send a server-side event with additional custom attributes.

# Set your Datadog credentials
export DD_API_KEY="<DD_API_KEY>"

# For sites other than datadoghq.com, replace the host below with: browser-intake-us3-datadoghq.com (us3.datadoghq.com), browser-intake-us5-datadoghq.com (us5.datadoghq.com), browser-intake-datadoghq.eu (datadoghq.eu), browser-intake-ap1-datadoghq.com (ap1.datadoghq.com), browser-intake-ap2-datadoghq.com (ap2.datadoghq.com), browser-intake-uk1-datadoghq.com (uk1.datadoghq.com)
curl -X POST "https://browser-intake-datadoghq.com/api/v2/prodlytics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-d @- << EOF
{
  "application": {
    "id": "123abcde-123a-123b-1234-123456789abc"
  },
  "customer": {
    "tier": "premium"
  },
  "event": {
    "name": "payment.processed"
  },
  "type": "server",
  "usr": {
    "id": "123"
  }
}
EOF

## Event with session ID
# Send a server-side event linked to a session.

# Set your Datadog credentials
export DD_API_KEY="<DD_API_KEY>"

# For sites other than datadoghq.com, replace the host below with: browser-intake-us3-datadoghq.com (us3.datadoghq.com), browser-intake-us5-datadoghq.com (us5.datadoghq.com), browser-intake-datadoghq.eu (datadoghq.eu), browser-intake-ap1-datadoghq.com (ap1.datadoghq.com), browser-intake-ap2-datadoghq.com (ap2.datadoghq.com), browser-intake-uk1-datadoghq.com (uk1.datadoghq.com)
curl -X POST "https://browser-intake-datadoghq.com/api/v2/prodlytics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-d @- << EOF
{
  "application": {
    "id": "123abcde-123a-123b-1234-123456789abc"
  },
  "event": {
    "name": "form.submitted"
  },
  "session": {
    "id": "session-789"
  },
  "type": "server"
}
EOF

## Simple event with user ID
# Send a server-side event linked to a user.

# Set your Datadog credentials
export DD_API_KEY="<DD_API_KEY>"

# For sites other than datadoghq.com, replace the host below with: browser-intake-us3-datadoghq.com (us3.datadoghq.com), browser-intake-us5-datadoghq.com (us5.datadoghq.com), browser-intake-datadoghq.eu (datadoghq.eu), browser-intake-ap1-datadoghq.com (ap1.datadoghq.com), browser-intake-ap2-datadoghq.com (ap2.datadoghq.com), browser-intake-uk1-datadoghq.com (uk1.datadoghq.com)
curl -X POST "https://browser-intake-datadoghq.com/api/v2/prodlytics" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "DD-API-KEY: ${DD_API_KEY}" \
-d @- << EOF
{
  "application": {
    "id": "123abcde-123a-123b-1234-123456789abc"
  },
  "event": {
    "name": "payment.processed"
  },
  "type": "server",
  "usr": {
    "id": "123"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Send server-side events returns "Request accepted for processing (always 202 empty JSON)." 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.ProductAnalyticsServerSideEventItem{
		Account: &datadogV2.ProductAnalyticsServerSideEventItemAccount{
			Id: "account-67890",
		},
		Application: datadogV2.ProductAnalyticsServerSideEventItemApplication{
			Id: "123abcde-123a-123b-1234-123456789abc",
		},
		Event: datadogV2.ProductAnalyticsServerSideEventItemEvent{
			Name: "payment.processed",
		},
		Session: &datadogV2.ProductAnalyticsServerSideEventItemSession{
			Id: "session-abcdef",
		},
		Type: datadogV2.PRODUCTANALYTICSSERVERSIDEEVENTITEMTYPE_SERVER,
		Usr: &datadogV2.ProductAnalyticsServerSideEventItemUsr{
			Id: "user-12345",
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewProductAnalyticsApi(apiClient)
	resp, r, err := api.SubmitProductAnalyticsEvent(ctx, body)

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

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `ProductAnalyticsApi.SubmitProductAnalyticsEvent`:\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_API_KEY="<DD_API_KEY>" go run "main.go"
```
{% /tab %}

{% tab label="Java" %}
```java
// Send server-side events returns "Request accepted for processing (always 202 empty JSON)."
// 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.ProductAnalyticsServerSideEventItem;
import com.datadog.api.client.v2.model.ProductAnalyticsServerSideEventItemAccount;
import com.datadog.api.client.v2.model.ProductAnalyticsServerSideEventItemApplication;
import com.datadog.api.client.v2.model.ProductAnalyticsServerSideEventItemEvent;
import com.datadog.api.client.v2.model.ProductAnalyticsServerSideEventItemSession;
import com.datadog.api.client.v2.model.ProductAnalyticsServerSideEventItemType;
import com.datadog.api.client.v2.model.ProductAnalyticsServerSideEventItemUsr;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = ApiClient.getDefaultApiClient();
    ProductAnalyticsApi apiInstance = new ProductAnalyticsApi(defaultClient);

    ProductAnalyticsServerSideEventItem body =
        new ProductAnalyticsServerSideEventItem()
            .account(new ProductAnalyticsServerSideEventItemAccount().id("account-67890"))
            .application(
                new ProductAnalyticsServerSideEventItemApplication()
                    .id("123abcde-123a-123b-1234-123456789abc"))
            .event(new ProductAnalyticsServerSideEventItemEvent().name("payment.processed"))
            .session(new ProductAnalyticsServerSideEventItemSession().id("session-abcdef"))
            .type(ProductAnalyticsServerSideEventItemType.SERVER)
            .usr(new ProductAnalyticsServerSideEventItemUsr().id("user-12345"));

    try {
      apiInstance.submitProductAnalyticsEvent(body);
    } catch (ApiException e) {
      System.err.println("Exception when calling ProductAnalyticsApi#submitProductAnalyticsEvent");
      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_API_KEY="<DD_API_KEY>" java "Example.java"
```
{% /tab %}

{% tab label="Python" %}
```python
"""
Send server-side events returns "Request accepted for processing (always 202 empty JSON)." 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_server_side_event_item import ProductAnalyticsServerSideEventItem
from datadog_api_client.v2.model.product_analytics_server_side_event_item_account import (
    ProductAnalyticsServerSideEventItemAccount,
)
from datadog_api_client.v2.model.product_analytics_server_side_event_item_application import (
    ProductAnalyticsServerSideEventItemApplication,
)
from datadog_api_client.v2.model.product_analytics_server_side_event_item_event import (
    ProductAnalyticsServerSideEventItemEvent,
)
from datadog_api_client.v2.model.product_analytics_server_side_event_item_session import (
    ProductAnalyticsServerSideEventItemSession,
)
from datadog_api_client.v2.model.product_analytics_server_side_event_item_type import (
    ProductAnalyticsServerSideEventItemType,
)
from datadog_api_client.v2.model.product_analytics_server_side_event_item_usr import (
    ProductAnalyticsServerSideEventItemUsr,
)

body = ProductAnalyticsServerSideEventItem(
    account=ProductAnalyticsServerSideEventItemAccount(
        id="account-67890",
    ),
    application=ProductAnalyticsServerSideEventItemApplication(
        id="123abcde-123a-123b-1234-123456789abc",
    ),
    event=ProductAnalyticsServerSideEventItemEvent(
        name="payment.processed",
    ),
    session=ProductAnalyticsServerSideEventItemSession(
        id="session-abcdef",
    ),
    type=ProductAnalyticsServerSideEventItemType.SERVER,
    usr=ProductAnalyticsServerSideEventItemUsr(
        id="user-12345",
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = ProductAnalyticsApi(api_client)
    response = api_instance.submit_product_analytics_event(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_API_KEY="<DD_API_KEY>" python3 "example.py"
```
{% /tab %}

{% tab label="Ruby" %}
```ruby
# Send server-side events returns "Request accepted for processing (always 202 empty JSON)." response

require "datadog_api_client"
api_instance = DatadogAPIClient::V2::ProductAnalyticsAPI.new

body = DatadogAPIClient::V2::ProductAnalyticsServerSideEventItem.new({
  account: DatadogAPIClient::V2::ProductAnalyticsServerSideEventItemAccount.new({
    id: "account-67890",
  }),
  application: DatadogAPIClient::V2::ProductAnalyticsServerSideEventItemApplication.new({
    id: "123abcde-123a-123b-1234-123456789abc",
  }),
  event: DatadogAPIClient::V2::ProductAnalyticsServerSideEventItemEvent.new({
    name: "payment.processed",
  }),
  session: DatadogAPIClient::V2::ProductAnalyticsServerSideEventItemSession.new({
    id: "session-abcdef",
  }),
  type: DatadogAPIClient::V2::ProductAnalyticsServerSideEventItemType::SERVER,
  usr: DatadogAPIClient::V2::ProductAnalyticsServerSideEventItemUsr.new({
    id: "user-12345",
  }),
})
p api_instance.submit_product_analytics_event(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_API_KEY="<DD_API_KEY>" rb "example.rb"
```
{% /tab %}

{% tab label="Rust" %}
```rust
// Send server-side events returns "Request accepted for processing (always 202
// empty JSON)." response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_product_analytics::ProductAnalyticsAPI;
use datadog_api_client::datadogV2::model::ProductAnalyticsServerSideEventItem;
use datadog_api_client::datadogV2::model::ProductAnalyticsServerSideEventItemAccount;
use datadog_api_client::datadogV2::model::ProductAnalyticsServerSideEventItemApplication;
use datadog_api_client::datadogV2::model::ProductAnalyticsServerSideEventItemEvent;
use datadog_api_client::datadogV2::model::ProductAnalyticsServerSideEventItemSession;
use datadog_api_client::datadogV2::model::ProductAnalyticsServerSideEventItemType;
use datadog_api_client::datadogV2::model::ProductAnalyticsServerSideEventItemUsr;

#[tokio::main]
async fn main() {
    let body = ProductAnalyticsServerSideEventItem::new(
        ProductAnalyticsServerSideEventItemApplication::new(
            "123abcde-123a-123b-1234-123456789abc".to_string(),
        ),
        ProductAnalyticsServerSideEventItemEvent::new("payment.processed".to_string()),
        ProductAnalyticsServerSideEventItemType::SERVER,
    )
    .account(ProductAnalyticsServerSideEventItemAccount::new(
        "account-67890".to_string(),
    ))
    .session(ProductAnalyticsServerSideEventItemSession::new(
        "session-abcdef".to_string(),
    ))
    .usr(ProductAnalyticsServerSideEventItemUsr::new(
        "user-12345".to_string(),
    ));
    let configuration = datadog::Configuration::new();
    let api = ProductAnalyticsAPI::with_config(configuration);
    let resp = api.submit_product_analytics_event(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>" cargo run
```
{% /tab %}

{% tab label="TypeScript" %}
```typescript
/**
 * Send server-side events returns "Request accepted for processing (always 202 empty JSON)." response
 */

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

const configuration = client.createConfiguration();
const apiInstance = new v2.ProductAnalyticsApi(configuration);

const params: v2.ProductAnalyticsApiSubmitProductAnalyticsEventRequest = {
  body: {
    account: {
      id: "account-67890",
    },
    application: {
      id: "123abcde-123a-123b-1234-123456789abc",
    },
    event: {
      name: "payment.processed",
    },
    session: {
      id: "session-abcdef",
    },
    type: "server",
    usr: {
      id: "user-12345",
    },
  },
};

apiInstance
  .submitProductAnalyticsEvent(params)
  .then((data: any) => {
    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_API_KEY="<DD_API_KEY>" tsc "example.ts"
```
{% /tab %}
{% /tabs %}
