---
title: Create On-Call escalation policy
description: Create a new On-Call escalation policy
breadcrumbs: Docs > API > Create On-Call escalation policy
---

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

# Create On-Call escalation policy

{% callout %}
This product or feature is not supported for the following sites: us2.ddog-gov.com
{% /callout %}

## v2 (latest)

| Datadog site      | API endpoint                                                          |
| ----------------- | --------------------------------------------------------------------- |
| app.datadoghq.com | POST https://api.datadoghq.com/api/v2/on-call/escalation-policies     |
| us3.datadoghq.com | POST https://api.us3.datadoghq.com/api/v2/on-call/escalation-policies |
| us5.datadoghq.com | POST https://api.us5.datadoghq.com/api/v2/on-call/escalation-policies |
| app.datadoghq.eu  | POST https://api.datadoghq.eu/api/v2/on-call/escalation-policies      |
| ap1.datadoghq.com | POST https://api.ap1.datadoghq.com/api/v2/on-call/escalation-policies |
| ap2.datadoghq.com | POST https://api.ap2.datadoghq.com/api/v2/on-call/escalation-policies |
| uk1.datadoghq.com | POST https://api.uk1.datadoghq.com/api/v2/on-call/escalation-policies |
| app.ddog-gov.com  | POST https://api.ddog-gov.com/api/v2/on-call/escalation-policies      |
| us2.ddog-gov.com  | POST https://api.us2.ddog-gov.com/api/v2/on-call/escalation-policies  |

### Overview

Create a new On-Call escalation policy

This endpoint requires the `on_call_write` permission.

### Arguments

#### Query Strings

| Field   | Type   | Description                                                                                                       |
| ------- | ------ | ----------------------------------------------------------------------------------------------------------------- |
| include | string | Comma-separated list of included relationships to be returned. Allowed values: `teams`, `steps`, `steps.targets`. |

### Request

#### Body Data (required)

{% tabs %}
{% tab label="Model" %}
| Parent field  | Field                      | Type     | Description                                                                                                                                 |
| ------------- | -------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|               | data [*required*]          | object   | Represents the data for creating an escalation policy, including its attributes, relationships, and resource type.                          |
| data          | attributes [*required*]    | object   | Defines the attributes for creating an escalation policy, including its description, name, resolution behavior, retries, and steps.         |
| attributes    | name [*required*]          | string   | Specifies the name for the new escalation policy.                                                                                           |
| attributes    | resolve_page_on_policy_end | boolean  | Indicates whether the page is automatically resolved when the policy ends.                                                                  |
| attributes    | retries                    | int64    | Specifies how many times the escalation sequence is retried if there is no response.                                                        |
| attributes    | steps [*required*]         | [object] | A list of escalation steps, each defining assignment, escalation timeout, and targets for the new policy.                                   |
| steps         | assignment                 | enum     | Specifies how this escalation step will assign targets (example `default` or `round-robin`). Allowed enum values: `default`, `round-robin`. |
| steps         | escalate_after_seconds     | int64    | Defines how many seconds to wait before escalating to the next step.                                                                        |
| steps         | targets [*required*]       | [object] | Specifies the collection of escalation targets for this step.                                                                               |
| targets       | config                     | object   | Configuration for an escalation target, such as schedule position.                                                                          |
| config        | schedule                   | object   | Schedule-specific configuration for an escalation target.                                                                                   |
| schedule      | position                   | enum     | Specifies the position of a schedule target (example `previous`, `current`, or `next`). Allowed enum values: `previous`, `current`, `next`. |
| targets       | id                         | string   | Specifies the unique identifier for this target.                                                                                            |
| targets       | type                       | enum     | Specifies the type of escalation target (example `users`, `schedules`, or `teams`). Allowed enum values: `users`, `schedules`, `teams`.     |
| data          | relationships              | object   | Represents relationships in an escalation policy creation request, including references to teams.                                           |
| relationships | teams                      | object   | Associates teams with this schedule in a data structure.                                                                                    |
| teams         | data                       | [object] | An array of team references for this schedule.                                                                                              |
| data          | id [*required*]            | string   | The unique identifier of the team in this relationship.                                                                                     |
| data          | type [*required*]          | enum     | Teams resource type. Allowed enum values: `teams`. Default: `teams`.                                                                        |
| data          | type [*required*]          | enum     | Indicates that the resource is of type `policies`. Allowed enum values: `policies`. Default: `policies`.                                    |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "name": "Example-On-Call",
      "resolve_page_on_policy_end": true,
      "retries": 2,
      "steps": [
        {
          "assignment": "default",
          "escalate_after_seconds": 3600,
          "targets": [
            {
              "id": "string",
              "type": "users"
            },
            {
              "id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d",
              "type": "schedules"
            },
            {
              "config": {
                "schedule": {
                  "position": "previous"
                }
              },
              "id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d",
              "type": "schedules"
            },
            {
              "id": "aeadc05e-98a8-11ec-ac2c-da7ad0900001",
              "type": "teams"
            }
          ]
        },
        {
          "assignment": "round-robin",
          "escalate_after_seconds": 3600,
          "targets": [
            {
              "id": "aeadc05e-98a8-11ec-ac2c-da7ad0900001",
              "type": "teams"
            }
          ]
        }
      ]
    },
    "relationships": {
      "teams": {
        "data": [
          {
            "id": "aeadc05e-98a8-11ec-ac2c-da7ad0900001",
            "type": "teams"
          }
        ]
      }
    },
    "type": "policies"
  }
}
```
{% /tab %}
{% /tabs %}

### Response

{% tabs %}
{% tab label="201" %}
Created

{% tabs %}
{% tab label="Model" %}
Represents a complete escalation policy response, including policy data and optionally included related resources.

| Parent field           | Field                      | Type      | Description                                                                                                                                                                         |
| ---------------------- | -------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                        | data                       | object    | Represents the data for a single escalation policy, including its attributes, ID, relationships, and resource type.                                                                 |
| data                   | attributes                 | object    | Defines the main attributes of an escalation policy, such as its name and behavior on policy end.                                                                                   |
| attributes             | name [*required*]          | string    | Specifies the name of the escalation policy.                                                                                                                                        |
| attributes             | resolve_page_on_policy_end | boolean   | Indicates whether the page is automatically resolved when the policy ends.                                                                                                          |
| attributes             | retries                    | int64     | Specifies how many times the escalation sequence is retried if there is no response.                                                                                                |
| attributes             | tags                       | [string]  | A list of tags attached to the escalation policy, in `key:value` format.                                                                                                            |
| data                   | id                         | string    | Specifies the unique identifier of the escalation policy.                                                                                                                           |
| data                   | relationships              | object    | Represents the relationships for an escalation policy, including references to steps and teams.                                                                                     |
| relationships          | steps [*required*]         | object    | Defines the relationship to a collection of steps within an escalation policy. Contains an array of step data references.                                                           |
| steps                  | data                       | [object]  | An array of references to the steps defined in this escalation policy.                                                                                                              |
| data                   | id [*required*]            | string    | Specifies the unique identifier for the step resource.                                                                                                                              |
| data                   | type [*required*]          | enum      | Indicates that the resource is of type `steps`. Allowed enum values: `steps`. Default: `steps`.                                                                                     |
| relationships          | teams                      | object    | Associates teams with this schedule in a data structure.                                                                                                                            |
| teams                  | data                       | [object]  | An array of team references for this schedule.                                                                                                                                      |
| data                   | id [*required*]            | string    | The unique identifier of the team in this relationship.                                                                                                                             |
| data                   | type [*required*]          | enum      | Teams resource type. Allowed enum values: `teams`. Default: `teams`.                                                                                                                |
| data                   | type [*required*]          | enum      | Indicates that the resource is of type `policies`. Allowed enum values: `policies`. Default: `policies`.                                                                            |
|                        | included                   | [<oneOf>] | Provides any included related resources, such as steps or targets, returned with the policy.                                                                                        |
| included               | <type=steps>               | object    | Represents a single step in an escalation policy, including its attributes, relationships, and resource type.                                                                       |
| <type=steps>           | attributes                 | object    | Defines attributes for an escalation policy step, such as assignment strategy and escalation timeout.                                                                               |
| attributes             | assignment                 | enum      | Specifies how this escalation step will assign targets (example `default` or `round-robin`). Allowed enum values: `default`, `round-robin`.                                         |
| attributes             | escalate_after_seconds     | int64     | Specifies how many seconds to wait before escalating to the next step.                                                                                                              |
| <type=steps>           | id                         | string    | Specifies the unique identifier of this escalation policy step.                                                                                                                     |
| <type=steps>           | relationships              | object    | Represents the relationship of an escalation policy step to its targets.                                                                                                            |
| relationships          | targets                    | object    | A list of escalation targets for a step                                                                                                                                             |
| targets                | data                       | [<oneOf>] | The `EscalationTargets` `data`.                                                                                                                                                     |
| data                   | <type=teams>               | object    | Represents a team target for an escalation policy step, including the team's ID and resource type.                                                                                  |
| <type=teams>           | id [*required*]            | string    | Specifies the unique identifier of the team resource.                                                                                                                               |
| <type=teams>           | type [*required*]          | enum      | Indicates that the resource is of type `teams`. Allowed enum values: `teams`. Default: `teams`.                                                                                     |
| data                   | <type=users>               | object    | Represents a user target for an escalation policy step, including the user's ID and resource type.                                                                                  |
| <type=users>           | id [*required*]            | string    | Specifies the unique identifier of the user resource.                                                                                                                               |
| <type=users>           | type [*required*]          | enum      | Indicates that the resource is of type `users`. Allowed enum values: `users`. Default: `users`.                                                                                     |
| data                   | <type=schedules>           | object    | Represents a schedule target for an escalation policy step, including its ID and resource type. This is a shortcut for a configured schedule target with position set to 'current'. |
| <type=schedules>       | id [*required*]            | string    | Specifies the unique identifier of the schedule resource.                                                                                                                           |
| <type=schedules>       | type [*required*]          | enum      | Indicates that the resource is of type `schedules`. Allowed enum values: `schedules`. Default: `schedules`.                                                                         |
| data                   | <type=schedule_target>     | object    | Relationship reference to a configured schedule target.                                                                                                                             |
| <type=schedule_target> | id [*required*]            | string    | Specifies the unique identifier of the configured schedule target.                                                                                                                  |
| <type=schedule_target> | type [*required*]          | enum      | Indicates that the resource is of type `schedule_target`. Allowed enum values: `schedule_target`. Default: `schedule_target`.                                                       |
| <type=steps>           | type [*required*]          | enum      | Indicates that the resource is of type `steps`. Allowed enum values: `steps`. Default: `steps`.                                                                                     |
| included               | <type=users>               | object    | Represents a user object in the context of an escalation policy, including their `id`, type, and basic attributes.                                                                  |
| <type=users>           | attributes                 | object    | Provides basic user information for an escalation policy, including a name and email address.                                                                                       |
| attributes             | color                      | string    | The user's on-call color, as a hex code (for example, `#FF0000`). Included only when `user.color` is requested in the `include` parameter.                                          |
| attributes             | email                      | string    | The user's email address.                                                                                                                                                           |
| attributes             | name                       | string    | The user's name.                                                                                                                                                                    |
| attributes             | status                     | enum      | The user's status. Allowed enum values: `active`, `deactivated`, `pending`.                                                                                                         |
| <type=users>           | id                         | string    | The unique user identifier.                                                                                                                                                         |
| <type=users>           | type [*required*]          | enum      | Users resource type. Allowed enum values: `users`. Default: `users`.                                                                                                                |
| included               | <type=schedules>           | object    | Represents the primary data object for a schedule, linking attributes and relationships.                                                                                            |
| <type=schedules>       | attributes                 | object    | Provides core properties of a schedule object such as its name and time zone.                                                                                                       |
| attributes             | max_responders             | int64     | Maximum number of users who can be on call at the same time. The value is between 1 and the number of layers, and no greater than 10.                                               |
| attributes             | name                       | string    | A short name for the schedule.                                                                                                                                                      |
| attributes             | tags                       | [string]  | A list of tags associated with the schedule.                                                                                                                                        |
| attributes             | time_zone                  | string    | The time zone in which this schedule operates.                                                                                                                                      |
| <type=schedules>       | id                         | string    | The schedule's unique identifier.                                                                                                                                                   |
| <type=schedules>       | relationships              | object    | Groups the relationships for a schedule object, referencing layers and teams.                                                                                                       |
| relationships          | layers                     | object    | Associates layers with this schedule in a data structure.                                                                                                                           |
| layers                 | data                       | [object]  | An array of layer references for this schedule.                                                                                                                                     |
| data                   | id [*required*]            | string    | The unique identifier of the layer in this relationship.                                                                                                                            |
| data                   | type [*required*]          | enum      | Layers resource type. Allowed enum values: `layers`. Default: `layers`.                                                                                                             |
| relationships          | teams                      | object    | Associates teams with this schedule in a data structure.                                                                                                                            |
| teams                  | data                       | [object]  | An array of team references for this schedule.                                                                                                                                      |
| data                   | id [*required*]            | string    | The unique identifier of the team in this relationship.                                                                                                                             |
| data                   | type [*required*]          | enum      | Teams resource type. Allowed enum values: `teams`. Default: `teams`.                                                                                                                |
| <type=schedules>       | type [*required*]          | enum      | Schedules resource type. Allowed enum values: `schedules`. Default: `schedules`.                                                                                                    |
| included               | <type=schedule_target>     | object    | Full resource representation of a configured schedule target with position (previous, current, or next).                                                                            |
| <type=schedule_target> | attributes [*required*]    | object    | Attributes for a configured schedule target, including position.                                                                                                                    |
| attributes             | position [*required*]      | enum      | Specifies the position of a schedule target (example `previous`, `current`, or `next`). Allowed enum values: `previous`, `current`, `next`.                                         |
| <type=schedule_target> | id [*required*]            | string    | Specifies the unique identifier of the configured schedule target.                                                                                                                  |
| <type=schedule_target> | relationships [*required*] | object    | Represents the relationships of a configured schedule target.                                                                                                                       |
| relationships          | schedule [*required*]      | object    | Holds the schedule reference for a configured schedule target.                                                                                                                      |
| schedule               | data [*required*]          | object    | Represents a schedule target for an escalation policy step, including its ID and resource type. This is a shortcut for a configured schedule target with position set to 'current'. |
| data                   | id [*required*]            | string    | Specifies the unique identifier of the schedule resource.                                                                                                                           |
| data                   | type [*required*]          | enum      | Indicates that the resource is of type `schedules`. Allowed enum values: `schedules`. Default: `schedules`.                                                                         |
| <type=schedule_target> | type [*required*]          | enum      | Indicates that the resource is of type `schedule_target`. Allowed enum values: `schedule_target`. Default: `schedule_target`.                                                       |
| included               | <type=teams>               | object    | Provides a reference to a team, including ID, type, and basic attributes/relationships.                                                                                             |
| <type=teams>           | attributes                 | object    | Encapsulates the basic attributes of a Team reference, such as name, handle, and an optional avatar or description.                                                                 |
| attributes             | avatar                     | string    | URL or reference for the team's avatar (if available).                                                                                                                              |
| attributes             | description                | string    | A short text describing the team.                                                                                                                                                   |
| attributes             | handle                     | string    | A unique handle/slug for the team.                                                                                                                                                  |
| attributes             | name                       | string    | The full, human-readable name of the team.                                                                                                                                          |
| <type=teams>           | id                         | string    | The team's unique identifier.                                                                                                                                                       |
| <type=teams>           | type [*required*]          | enum      | Teams resource type. Allowed enum values: `teams`. Default: `teams`.                                                                                                                |
{% /tab %}

{% tab label="Example" %}
```json
{
  "data": {
    "attributes": {
      "name": "Escalation Policy 1",
      "resolve_page_on_policy_end": true,
      "retries": 2
    },
    "id": "00000000-aba1-0000-0000-000000000000",
    "relationships": {
      "steps": {
        "data": [
          {
            "id": "00000000-aba1-0000-0000-000000000000",
            "type": "steps"
          }
        ]
      },
      "teams": {
        "data": [
          {
            "id": "00000000-da3a-0000-0000-000000000000",
            "type": "teams"
          }
        ]
      }
    },
    "type": "policies"
  },
  "included": [
    {
      "attributes": {
        "avatar": "",
        "description": "Team 1 description",
        "handle": "team1",
        "name": "Team 1"
      },
      "id": "00000000-da3a-0000-0000-000000000000",
      "type": "teams"
    },
    {
      "attributes": {
        "assignment": "default",
        "escalate_after_seconds": 3600
      },
      "id": "00000000-aba1-0000-0000-000000000000",
      "relationships": {
        "targets": {
          "data": [
            {
              "id": "00000000-aba1-0000-0000-000000000000",
              "type": "users"
            },
            {
              "id": "00000000-aba2-0000-0000-000000000000",
              "type": "schedules"
            },
            {
              "id": "00000000-aba2-0000-0000-000000000000_previous",
              "type": "schedule_target"
            },
            {
              "id": "00000000-aba3-0000-0000-000000000000",
              "type": "teams"
            }
          ]
        }
      },
      "type": "steps"
    },
    {
      "id": "00000000-aba1-0000-0000-000000000000",
      "type": "users"
    },
    {
      "id": "00000000-aba2-0000-0000-000000000000",
      "type": "schedules"
    },
    {
      "attributes": {
        "position": "previous"
      },
      "id": "00000000-aba2-0000-0000-000000000000_previous",
      "relationships": {
        "schedule": {
          "data": {
            "id": "00000000-aba2-0000-0000-000000000000",
            "type": "schedules"
          }
        }
      },
      "type": "schedule_target"
    },
    {
      "id": "00000000-aba3-0000-0000-000000000000",
      "type": "teams"
    }
  ]
}
```
{% /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="401" %}
Unauthorized

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

{% 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 %}
{% /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/on-call/escalation-policies" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${DD_BEARER_TOKEN}" \
-d @- << EOF
{
  "data": {
    "attributes": {
      "name": "Example-On-Call",
      "resolve_page_on_policy_end": true,
      "retries": 2,
      "steps": [
        {
          "assignment": "default",
          "escalate_after_seconds": 3600,
          "targets": [
            {
              "id": "string",
              "type": "users"
            },
            {
              "id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d",
              "type": "schedules"
            },
            {
              "config": {
                "schedule": {
                  "position": "previous"
                }
              },
              "id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d",
              "type": "schedules"
            },
            {
              "id": "aeadc05e-98a8-11ec-ac2c-da7ad0900001",
              "type": "teams"
            }
          ]
        },
        {
          "assignment": "round-robin",
          "escalate_after_seconds": 3600,
          "targets": [
            {
              "id": "aeadc05e-98a8-11ec-ac2c-da7ad0900001",
              "type": "teams"
            }
          ]
        }
      ]
    },
    "relationships": {
      "teams": {
        "data": [
          {
            "id": "aeadc05e-98a8-11ec-ac2c-da7ad0900001",
            "type": "teams"
          }
        ]
      }
    },
    "type": "policies"
  }
}
EOF
```
{% /tab %}

{% tab label="Go" %}
```go
// Create On-Call escalation policy returns "Created" 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() {
	// there is a valid "user" in the system
	UserDataID := os.Getenv("USER_DATA_ID")

	// there is a valid "schedule" in the system
	ScheduleDataID := os.Getenv("SCHEDULE_DATA_ID")

	// there is a valid "dd_team" in the system
	DdTeamDataID := os.Getenv("DD_TEAM_DATA_ID")

	body := datadogV2.EscalationPolicyCreateRequest{
		Data: datadogV2.EscalationPolicyCreateRequestData{
			Attributes: datadogV2.EscalationPolicyCreateRequestDataAttributes{
				Name:                   "Example-On-Call",
				ResolvePageOnPolicyEnd: datadog.PtrBool(true),
				Retries:                datadog.PtrInt64(2),
				Steps: []datadogV2.EscalationPolicyCreateRequestDataAttributesStepsItems{
					{
						Assignment:           datadogV2.ESCALATIONPOLICYSTEPATTRIBUTESASSIGNMENT_DEFAULT.Ptr(),
						EscalateAfterSeconds: datadog.PtrInt64(3600),
						Targets: []datadogV2.EscalationPolicyStepTarget{
							{
								Id:   datadog.PtrString(UserDataID),
								Type: datadogV2.ESCALATIONPOLICYSTEPTARGETTYPE_USERS.Ptr(),
							},
							{
								Id:   datadog.PtrString(ScheduleDataID),
								Type: datadogV2.ESCALATIONPOLICYSTEPTARGETTYPE_SCHEDULES.Ptr(),
							},
							{
								Config: &datadogV2.EscalationPolicyStepTargetConfig{
									Schedule: &datadogV2.EscalationPolicyStepTargetConfigSchedule{
										Position: datadogV2.SCHEDULETARGETPOSITION_PREVIOUS.Ptr(),
									},
								},
								Id:   datadog.PtrString(ScheduleDataID),
								Type: datadogV2.ESCALATIONPOLICYSTEPTARGETTYPE_SCHEDULES.Ptr(),
							},
							{
								Id:   datadog.PtrString(DdTeamDataID),
								Type: datadogV2.ESCALATIONPOLICYSTEPTARGETTYPE_TEAMS.Ptr(),
							},
						},
					},
					{
						Assignment:           datadogV2.ESCALATIONPOLICYSTEPATTRIBUTESASSIGNMENT_ROUND_ROBIN.Ptr(),
						EscalateAfterSeconds: datadog.PtrInt64(3600),
						Targets: []datadogV2.EscalationPolicyStepTarget{
							{
								Id:   datadog.PtrString(DdTeamDataID),
								Type: datadogV2.ESCALATIONPOLICYSTEPTARGETTYPE_TEAMS.Ptr(),
							},
						},
					},
				},
			},
			Relationships: &datadogV2.EscalationPolicyCreateRequestDataRelationships{
				Teams: &datadogV2.DataRelationshipsTeams{
					Data: []datadogV2.DataRelationshipsTeamsDataItems{
						{
							Id:   DdTeamDataID,
							Type: datadogV2.DATARELATIONSHIPSTEAMSDATAITEMSTYPE_TEAMS,
						},
					},
				},
			},
			Type: datadogV2.ESCALATIONPOLICYCREATEREQUESTDATATYPE_POLICIES,
		},
	}
	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.NewOnCallApi(apiClient)
	resp, r, err := api.CreateOnCallEscalationPolicy(ctx, body, *datadogV2.NewCreateOnCallEscalationPolicyOptionalParameters().WithInclude("steps.targets"))

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

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `OnCallApi.CreateOnCallEscalationPolicy`:\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
// Create On-Call escalation policy returns "Created" response

import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.OnCallApi;
import com.datadog.api.client.v2.api.OnCallApi.CreateOnCallEscalationPolicyOptionalParameters;
import com.datadog.api.client.v2.model.DataRelationshipsTeams;
import com.datadog.api.client.v2.model.DataRelationshipsTeamsDataItems;
import com.datadog.api.client.v2.model.DataRelationshipsTeamsDataItemsType;
import com.datadog.api.client.v2.model.EscalationPolicy;
import com.datadog.api.client.v2.model.EscalationPolicyCreateRequest;
import com.datadog.api.client.v2.model.EscalationPolicyCreateRequestData;
import com.datadog.api.client.v2.model.EscalationPolicyCreateRequestDataAttributes;
import com.datadog.api.client.v2.model.EscalationPolicyCreateRequestDataAttributesStepsItems;
import com.datadog.api.client.v2.model.EscalationPolicyCreateRequestDataRelationships;
import com.datadog.api.client.v2.model.EscalationPolicyCreateRequestDataType;
import com.datadog.api.client.v2.model.EscalationPolicyStepAttributesAssignment;
import com.datadog.api.client.v2.model.EscalationPolicyStepTarget;
import com.datadog.api.client.v2.model.EscalationPolicyStepTargetConfig;
import com.datadog.api.client.v2.model.EscalationPolicyStepTargetConfigSchedule;
import com.datadog.api.client.v2.model.EscalationPolicyStepTargetType;
import com.datadog.api.client.v2.model.ScheduleTargetPosition;
import java.util.Arrays;
import java.util.Collections;

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

    // there is a valid "user" in the system
    String USER_DATA_ID = System.getenv("USER_DATA_ID");

    // there is a valid "schedule" in the system
    String SCHEDULE_DATA_ID = System.getenv("SCHEDULE_DATA_ID");

    // there is a valid "dd_team" in the system
    String DD_TEAM_DATA_ID = System.getenv("DD_TEAM_DATA_ID");

    EscalationPolicyCreateRequest body =
        new EscalationPolicyCreateRequest()
            .data(
                new EscalationPolicyCreateRequestData()
                    .attributes(
                        new EscalationPolicyCreateRequestDataAttributes()
                            .name("Example-On-Call")
                            .resolvePageOnPolicyEnd(true)
                            .retries(2L)
                            .steps(
                                Arrays.asList(
                                    new EscalationPolicyCreateRequestDataAttributesStepsItems()
                                        .assignment(
                                            EscalationPolicyStepAttributesAssignment.DEFAULT)
                                        .escalateAfterSeconds(3600L)
                                        .targets(
                                            Arrays.asList(
                                                new EscalationPolicyStepTarget()
                                                    .id(USER_DATA_ID)
                                                    .type(EscalationPolicyStepTargetType.USERS),
                                                new EscalationPolicyStepTarget()
                                                    .id(SCHEDULE_DATA_ID)
                                                    .type(EscalationPolicyStepTargetType.SCHEDULES),
                                                new EscalationPolicyStepTarget()
                                                    .config(
                                                        new EscalationPolicyStepTargetConfig()
                                                            .schedule(
                                                                new EscalationPolicyStepTargetConfigSchedule()
                                                                    .position(
                                                                        ScheduleTargetPosition
                                                                            .PREVIOUS)))
                                                    .id(SCHEDULE_DATA_ID)
                                                    .type(EscalationPolicyStepTargetType.SCHEDULES),
                                                new EscalationPolicyStepTarget()
                                                    .id(DD_TEAM_DATA_ID)
                                                    .type(EscalationPolicyStepTargetType.TEAMS))),
                                    new EscalationPolicyCreateRequestDataAttributesStepsItems()
                                        .assignment(
                                            EscalationPolicyStepAttributesAssignment.ROUND_ROBIN)
                                        .escalateAfterSeconds(3600L)
                                        .targets(
                                            Collections.singletonList(
                                                new EscalationPolicyStepTarget()
                                                    .id(DD_TEAM_DATA_ID)
                                                    .type(EscalationPolicyStepTargetType.TEAMS))))))
                    .relationships(
                        new EscalationPolicyCreateRequestDataRelationships()
                            .teams(
                                new DataRelationshipsTeams()
                                    .data(
                                        Collections.singletonList(
                                            new DataRelationshipsTeamsDataItems()
                                                .id(DD_TEAM_DATA_ID)
                                                .type(DataRelationshipsTeamsDataItemsType.TEAMS)))))
                    .type(EscalationPolicyCreateRequestDataType.POLICIES));

    try {
      EscalationPolicy result =
          apiInstance.createOnCallEscalationPolicy(
              body, new CreateOnCallEscalationPolicyOptionalParameters().include("steps.targets"));
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling OnCallApi#createOnCallEscalationPolicy");
      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
"""
Create On-Call escalation policy returns "Created" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.on_call_api import OnCallApi
from datadog_api_client.v2.model.data_relationships_teams import DataRelationshipsTeams
from datadog_api_client.v2.model.data_relationships_teams_data_items import DataRelationshipsTeamsDataItems
from datadog_api_client.v2.model.data_relationships_teams_data_items_type import DataRelationshipsTeamsDataItemsType
from datadog_api_client.v2.model.escalation_policy_create_request import EscalationPolicyCreateRequest
from datadog_api_client.v2.model.escalation_policy_create_request_data import EscalationPolicyCreateRequestData
from datadog_api_client.v2.model.escalation_policy_create_request_data_attributes import (
    EscalationPolicyCreateRequestDataAttributes,
)
from datadog_api_client.v2.model.escalation_policy_create_request_data_attributes_steps_items import (
    EscalationPolicyCreateRequestDataAttributesStepsItems,
)
from datadog_api_client.v2.model.escalation_policy_create_request_data_relationships import (
    EscalationPolicyCreateRequestDataRelationships,
)
from datadog_api_client.v2.model.escalation_policy_create_request_data_type import EscalationPolicyCreateRequestDataType
from datadog_api_client.v2.model.escalation_policy_step_attributes_assignment import (
    EscalationPolicyStepAttributesAssignment,
)
from datadog_api_client.v2.model.escalation_policy_step_target import EscalationPolicyStepTarget
from datadog_api_client.v2.model.escalation_policy_step_target_config import EscalationPolicyStepTargetConfig
from datadog_api_client.v2.model.escalation_policy_step_target_config_schedule import (
    EscalationPolicyStepTargetConfigSchedule,
)
from datadog_api_client.v2.model.escalation_policy_step_target_type import EscalationPolicyStepTargetType
from datadog_api_client.v2.model.schedule_target_position import ScheduleTargetPosition

# there is a valid "user" in the system
USER_DATA_ID = environ["USER_DATA_ID"]

# there is a valid "schedule" in the system
SCHEDULE_DATA_ID = environ["SCHEDULE_DATA_ID"]

# there is a valid "dd_team" in the system
DD_TEAM_DATA_ID = environ["DD_TEAM_DATA_ID"]

body = EscalationPolicyCreateRequest(
    data=EscalationPolicyCreateRequestData(
        attributes=EscalationPolicyCreateRequestDataAttributes(
            name="Example-On-Call",
            resolve_page_on_policy_end=True,
            retries=2,
            steps=[
                EscalationPolicyCreateRequestDataAttributesStepsItems(
                    assignment=EscalationPolicyStepAttributesAssignment.DEFAULT,
                    escalate_after_seconds=3600,
                    targets=[
                        EscalationPolicyStepTarget(
                            id=USER_DATA_ID,
                            type=EscalationPolicyStepTargetType.USERS,
                        ),
                        EscalationPolicyStepTarget(
                            id=SCHEDULE_DATA_ID,
                            type=EscalationPolicyStepTargetType.SCHEDULES,
                        ),
                        EscalationPolicyStepTarget(
                            config=EscalationPolicyStepTargetConfig(
                                schedule=EscalationPolicyStepTargetConfigSchedule(
                                    position=ScheduleTargetPosition.PREVIOUS,
                                ),
                            ),
                            id=SCHEDULE_DATA_ID,
                            type=EscalationPolicyStepTargetType.SCHEDULES,
                        ),
                        EscalationPolicyStepTarget(
                            id=DD_TEAM_DATA_ID,
                            type=EscalationPolicyStepTargetType.TEAMS,
                        ),
                    ],
                ),
                EscalationPolicyCreateRequestDataAttributesStepsItems(
                    assignment=EscalationPolicyStepAttributesAssignment.ROUND_ROBIN,
                    escalate_after_seconds=3600,
                    targets=[
                        EscalationPolicyStepTarget(
                            id=DD_TEAM_DATA_ID,
                            type=EscalationPolicyStepTargetType.TEAMS,
                        ),
                    ],
                ),
            ],
        ),
        relationships=EscalationPolicyCreateRequestDataRelationships(
            teams=DataRelationshipsTeams(
                data=[
                    DataRelationshipsTeamsDataItems(
                        id=DD_TEAM_DATA_ID,
                        type=DataRelationshipsTeamsDataItemsType.TEAMS,
                    ),
                ],
            ),
        ),
        type=EscalationPolicyCreateRequestDataType.POLICIES,
    ),
)

configuration = Configuration()
configuration.access_token = environ["DD_BEARER_TOKEN"]
with ApiClient(configuration) as api_client:
    api_instance = OnCallApi(api_client)
    response = api_instance.create_on_call_escalation_policy(include="steps.targets", 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
# Create On-Call escalation policy returns "Created" response

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

# there is a valid "user" in the system
USER_DATA_ID = ENV["USER_DATA_ID"]

# there is a valid "schedule" in the system
SCHEDULE_DATA_ID = ENV["SCHEDULE_DATA_ID"]

# there is a valid "dd_team" in the system
DD_TEAM_DATA_ID = ENV["DD_TEAM_DATA_ID"]

body = DatadogAPIClient::V2::EscalationPolicyCreateRequest.new({
  data: DatadogAPIClient::V2::EscalationPolicyCreateRequestData.new({
    attributes: DatadogAPIClient::V2::EscalationPolicyCreateRequestDataAttributes.new({
      name: "Example-On-Call",
      resolve_page_on_policy_end: true,
      retries: 2,
      steps: [
        DatadogAPIClient::V2::EscalationPolicyCreateRequestDataAttributesStepsItems.new({
          assignment: DatadogAPIClient::V2::EscalationPolicyStepAttributesAssignment::DEFAULT,
          escalate_after_seconds: 3600,
          targets: [
            DatadogAPIClient::V2::EscalationPolicyStepTarget.new({
              id: USER_DATA_ID,
              type: DatadogAPIClient::V2::EscalationPolicyStepTargetType::USERS,
            }),
            DatadogAPIClient::V2::EscalationPolicyStepTarget.new({
              id: SCHEDULE_DATA_ID,
              type: DatadogAPIClient::V2::EscalationPolicyStepTargetType::SCHEDULES,
            }),
            DatadogAPIClient::V2::EscalationPolicyStepTarget.new({
              config: DatadogAPIClient::V2::EscalationPolicyStepTargetConfig.new({
                schedule: DatadogAPIClient::V2::EscalationPolicyStepTargetConfigSchedule.new({
                  position: DatadogAPIClient::V2::ScheduleTargetPosition::PREVIOUS,
                }),
              }),
              id: SCHEDULE_DATA_ID,
              type: DatadogAPIClient::V2::EscalationPolicyStepTargetType::SCHEDULES,
            }),
            DatadogAPIClient::V2::EscalationPolicyStepTarget.new({
              id: DD_TEAM_DATA_ID,
              type: DatadogAPIClient::V2::EscalationPolicyStepTargetType::TEAMS,
            }),
          ],
        }),
        DatadogAPIClient::V2::EscalationPolicyCreateRequestDataAttributesStepsItems.new({
          assignment: DatadogAPIClient::V2::EscalationPolicyStepAttributesAssignment::ROUND_ROBIN,
          escalate_after_seconds: 3600,
          targets: [
            DatadogAPIClient::V2::EscalationPolicyStepTarget.new({
              id: DD_TEAM_DATA_ID,
              type: DatadogAPIClient::V2::EscalationPolicyStepTargetType::TEAMS,
            }),
          ],
        }),
      ],
    }),
    relationships: DatadogAPIClient::V2::EscalationPolicyCreateRequestDataRelationships.new({
      teams: DatadogAPIClient::V2::DataRelationshipsTeams.new({
        data: [
          DatadogAPIClient::V2::DataRelationshipsTeamsDataItems.new({
            id: DD_TEAM_DATA_ID,
            type: DatadogAPIClient::V2::DataRelationshipsTeamsDataItemsType::TEAMS,
          }),
        ],
      }),
    }),
    type: DatadogAPIClient::V2::EscalationPolicyCreateRequestDataType::POLICIES,
  }),
})
opts = {
  include: "steps.targets",
}
p api_instance.create_on_call_escalation_policy(body, opts)
```

#### 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
// Create On-Call escalation policy returns "Created" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_on_call::CreateOnCallEscalationPolicyOptionalParams;
use datadog_api_client::datadogV2::api_on_call::OnCallAPI;
use datadog_api_client::datadogV2::model::DataRelationshipsTeams;
use datadog_api_client::datadogV2::model::DataRelationshipsTeamsDataItems;
use datadog_api_client::datadogV2::model::DataRelationshipsTeamsDataItemsType;
use datadog_api_client::datadogV2::model::EscalationPolicyCreateRequest;
use datadog_api_client::datadogV2::model::EscalationPolicyCreateRequestData;
use datadog_api_client::datadogV2::model::EscalationPolicyCreateRequestDataAttributes;
use datadog_api_client::datadogV2::model::EscalationPolicyCreateRequestDataAttributesStepsItems;
use datadog_api_client::datadogV2::model::EscalationPolicyCreateRequestDataRelationships;
use datadog_api_client::datadogV2::model::EscalationPolicyCreateRequestDataType;
use datadog_api_client::datadogV2::model::EscalationPolicyStepAttributesAssignment;
use datadog_api_client::datadogV2::model::EscalationPolicyStepTarget;
use datadog_api_client::datadogV2::model::EscalationPolicyStepTargetConfig;
use datadog_api_client::datadogV2::model::EscalationPolicyStepTargetConfigSchedule;
use datadog_api_client::datadogV2::model::EscalationPolicyStepTargetType;
use datadog_api_client::datadogV2::model::ScheduleTargetPosition;

#[tokio::main]
async fn main() {
    // there is a valid "user" in the system
    let user_data_id = std::env::var("USER_DATA_ID").unwrap();

    // there is a valid "schedule" in the system
    let schedule_data_id = std::env::var("SCHEDULE_DATA_ID").unwrap();

    // there is a valid "dd_team" in the system
    let dd_team_data_id = std::env::var("DD_TEAM_DATA_ID").unwrap();
    let body = EscalationPolicyCreateRequest::new(
        EscalationPolicyCreateRequestData::new(
            EscalationPolicyCreateRequestDataAttributes::new(
                "Example-On-Call".to_string(),
                vec![
                    EscalationPolicyCreateRequestDataAttributesStepsItems::new(vec![
                        EscalationPolicyStepTarget::new()
                            .id(user_data_id.clone())
                            .type_(EscalationPolicyStepTargetType::USERS),
                        EscalationPolicyStepTarget::new()
                            .id(schedule_data_id.clone())
                            .type_(EscalationPolicyStepTargetType::SCHEDULES),
                        EscalationPolicyStepTarget::new()
                            .config(
                                EscalationPolicyStepTargetConfig::new().schedule(
                                    EscalationPolicyStepTargetConfigSchedule::new()
                                        .position(ScheduleTargetPosition::PREVIOUS),
                                ),
                            )
                            .id(schedule_data_id.clone())
                            .type_(EscalationPolicyStepTargetType::SCHEDULES),
                        EscalationPolicyStepTarget::new()
                            .id(dd_team_data_id.clone())
                            .type_(EscalationPolicyStepTargetType::TEAMS),
                    ])
                    .assignment(EscalationPolicyStepAttributesAssignment::DEFAULT)
                    .escalate_after_seconds(3600),
                    EscalationPolicyCreateRequestDataAttributesStepsItems::new(vec![
                        EscalationPolicyStepTarget::new()
                            .id(dd_team_data_id.clone())
                            .type_(EscalationPolicyStepTargetType::TEAMS),
                    ])
                    .assignment(EscalationPolicyStepAttributesAssignment::ROUND_ROBIN)
                    .escalate_after_seconds(3600),
                ],
            )
            .resolve_page_on_policy_end(true)
            .retries(2),
            EscalationPolicyCreateRequestDataType::POLICIES,
        )
        .relationships(EscalationPolicyCreateRequestDataRelationships::new().teams(
            DataRelationshipsTeams::new().data(vec![DataRelationshipsTeamsDataItems::new(
                dd_team_data_id.clone(),
                DataRelationshipsTeamsDataItemsType::TEAMS,
            )]),
        )),
    );
    let configuration = datadog::Configuration::new();
    let api = OnCallAPI::with_config(configuration);
    let resp = api
        .create_on_call_escalation_policy(
            body,
            CreateOnCallEscalationPolicyOptionalParams::default()
                .include("steps.targets".to_string()),
        )
        .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
/**
 * Create On-Call escalation policy returns "Created" 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.OnCallApi(configuration);

// there is a valid "user" in the system
const USER_DATA_ID = process.env.USER_DATA_ID as string;

// there is a valid "schedule" in the system
const SCHEDULE_DATA_ID = process.env.SCHEDULE_DATA_ID as string;

// there is a valid "dd_team" in the system
const DD_TEAM_DATA_ID = process.env.DD_TEAM_DATA_ID as string;

const params: v2.OnCallApiCreateOnCallEscalationPolicyRequest = {
  body: {
    data: {
      attributes: {
        name: "Example-On-Call",
        resolvePageOnPolicyEnd: true,
        retries: 2,
        steps: [
          {
            assignment: "default",
            escalateAfterSeconds: 3600,
            targets: [
              {
                id: USER_DATA_ID,
                type: "users",
              },
              {
                id: SCHEDULE_DATA_ID,
                type: "schedules",
              },
              {
                config: {
                  schedule: {
                    position: "previous",
                  },
                },
                id: SCHEDULE_DATA_ID,
                type: "schedules",
              },
              {
                id: DD_TEAM_DATA_ID,
                type: "teams",
              },
            ],
          },
          {
            assignment: "round-robin",
            escalateAfterSeconds: 3600,
            targets: [
              {
                id: DD_TEAM_DATA_ID,
                type: "teams",
              },
            ],
          },
        ],
      },
      relationships: {
        teams: {
          data: [
            {
              id: DD_TEAM_DATA_ID,
              type: "teams",
            },
          ],
        },
      },
      type: "policies",
    },
  },
  include: "steps.targets",
};

apiInstance
  .createOnCallEscalationPolicy(params)
  .then((data: v2.EscalationPolicy) => {
    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 %}
