---
title: Set On-Call team routing rules
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: Docs > API Reference > On-Call
---

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

# Set On-Call team routing rules{% #set-on-call-team-routing-rules %}
Copy pageCopied
{% tab title="v2" %}

| Datadog site      | API endpoint                                                                   |
| ----------------- | ------------------------------------------------------------------------------ |
| ap1.datadoghq.com | PUT https://api.ap1.datadoghq.com/api/v2/on-call/teams/{team_id}/routing-rules |
| ap2.datadoghq.com | PUT https://api.ap2.datadoghq.com/api/v2/on-call/teams/{team_id}/routing-rules |
| app.datadoghq.eu  | PUT https://api.datadoghq.eu/api/v2/on-call/teams/{team_id}/routing-rules      |
| app.ddog-gov.com  | PUT https://api.ddog-gov.com/api/v2/on-call/teams/{team_id}/routing-rules      |
| us2.ddog-gov.com  | PUT https://api.us2.ddog-gov.com/api/v2/on-call/teams/{team_id}/routing-rules  |
| app.datadoghq.com | PUT https://api.datadoghq.com/api/v2/on-call/teams/{team_id}/routing-rules     |
| us3.datadoghq.com | PUT https://api.us3.datadoghq.com/api/v2/on-call/teams/{team_id}/routing-rules |
| us5.datadoghq.com | PUT https://api.us5.datadoghq.com/api/v2/on-call/teams/{team_id}/routing-rules |

### Overview

Set a team's On-Call routing rules This endpoint requires the `on_call_write` permission.

### Arguments

#### Path Parameters

| Name                      | Type   | Description |
| ------------------------- | ------ | ----------- |
| team_id [*required*] | string | The team ID |

#### Query Strings

| Name    | Type   | Description                                                                                             |
| ------- | ------ | ------------------------------------------------------------------------------------------------------- |
| include | string | Comma-separated list of included relationships to be returned. Allowed values: `rules`, `rules.policy`. |

### Request

#### Body Data (required)



{% tab title="Model" %}

| Parent field     | Field                          | Type            | Description                                                                                                                                                                                                                                                                           |
| ---------------- | ------------------------------ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                  | data                           | object          | Holds the data necessary to create or update team routing rules, including attributes, ID, and resource type.                                                                                                                                                                         |
| data             | attributes                     | object          | Represents the attributes of a request to update or create team routing rules.                                                                                                                                                                                                        |
| attributes       | rules                          | [object]        | A list of routing rule items that define how incoming pages should be handled.                                                                                                                                                                                                        |
| rules            | actions                        | [ <oneOf>] | Specifies the list of actions to perform when the routing rule is matched.                                                                                                                                                                                                            |
| actions          | Option 1                       | object          | Sends a message to a Slack channel.                                                                                                                                                                                                                                                   |
| Option 1         | channel [*required*]      | string          | The channel ID.                                                                                                                                                                                                                                                                       |
| Option 1         | type [*required*]         | enum            | Indicates that the action is a send Slack message action. Allowed enum values: `send_slack_message`                                                                                                                                                                                   |
| Option 1         | workspace [*required*]    | string          | The workspace ID.                                                                                                                                                                                                                                                                     |
| actions          | Option 2                       | object          | Sends a message to a Microsoft Teams channel.                                                                                                                                                                                                                                         |
| Option 2         | channel [*required*]      | string          | The channel ID.                                                                                                                                                                                                                                                                       |
| Option 2         | team [*required*]         | string          | The team ID.                                                                                                                                                                                                                                                                          |
| Option 2         | tenant [*required*]       | string          | The tenant ID.                                                                                                                                                                                                                                                                        |
| Option 2         | type [*required*]         | enum            | Indicates that the action is a send Microsoft Teams message action. Allowed enum values: `send_teams_message`                                                                                                                                                                         |
| actions          | Option 3                       | object          | Triggers a Workflow Automation.                                                                                                                                                                                                                                                       |
| Option 3         | handle [*required*]       | string          | The handle of the Workflow Automation to trigger.                                                                                                                                                                                                                                     |
| Option 3         | type [*required*]         | enum            | Indicates that the action triggers a Workflow Automation. Allowed enum values: `workflow`                                                                                                                                                                                             |
| actions          | Option 4                       | object          | Triggers an escalation policy.                                                                                                                                                                                                                                                        |
| Option 4         | ack_timeout_minutes            | int64           | The number of minutes before an acknowledged page is re-triggered.                                                                                                                                                                                                                    |
| Option 4         | policy_id [*required*]    | string          | The ID of the escalation policy to route to.                                                                                                                                                                                                                                          |
| Option 4         | support_hours                  | object          | Support hours during which the escalation policy will be executed. Outside of these hours, the escalation policy will be on hold and triggered once the next support hours window starts. This is mutually exclusive with the top-level `time_restriction` field on the routing rule. |
| support_hours    | restrictions                   | [object]        | The list of support hours time windows.                                                                                                                                                                                                                                               |
| restrictions     | end_day                        | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | end_time                       | string          | Specifies the ending time for this restriction.                                                                                                                                                                                                                                       |
| restrictions     | start_day                      | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | start_time                     | string          | Specifies the starting time for this restriction.                                                                                                                                                                                                                                     |
| support_hours    | time_zone [*required*]    | string          | The time zone in which the support hours are expressed.                                                                                                                                                                                                                               |
| Option 4         | type [*required*]         | enum            | Indicates that the action pages an escalation policy. This action can be set once per routing rule item, and is mutually exclusive with the top-level `policy_id` field on the routing rule. Allowed enum values: `escalation_policy`                                                 |
| Option 4         | urgency                        | enum            | Specifies the level of urgency for a routing rule (low, high, or dynamic). Allowed enum values: `low,high,dynamic`                                                                                                                                                                    |
| rules            | policy_id                      | string          | Identifies the policy to be applied when this routing rule matches.                                                                                                                                                                                                                   |
| rules            | query                          | string          | Defines the query or condition that triggers this routing rule.                                                                                                                                                                                                                       |
| rules            | time_restriction               | object          | Time restrictions during which the routing rule is active. Outside of these hours, the rule does not match and routing continues to subsequent rules. This is mutually exclusive with the action-level `support_hours` field.                                                         |
| time_restriction | restrictions [*required*] | [object]        | Defines the list of time-based restrictions.                                                                                                                                                                                                                                          |
| restrictions     | end_day                        | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | end_time                       | string          | Specifies the ending time for this restriction.                                                                                                                                                                                                                                       |
| restrictions     | start_day                      | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | start_time                     | string          | Specifies the starting time for this restriction.                                                                                                                                                                                                                                     |
| time_restriction | time_zone [*required*]    | string          | Specifies the time zone applicable to the restrictions.                                                                                                                                                                                                                               |
| rules            | urgency                        | enum            | Specifies the level of urgency for a routing rule (low, high, or dynamic). Allowed enum values: `low,high,dynamic`                                                                                                                                                                    |
| data             | id                             | string          | Specifies the unique identifier for this set of team routing rules.                                                                                                                                                                                                                   |
| data             | type [*required*]         | enum            | Team routing rules resource type. Allowed enum values: `team_routing_rules`                                                                                                                                                                                                           |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "attributes": {
      "rules": [
        {
          "actions": [
            {
              "type": "escalation_policy",
              "policy_id": "ab000000-0000-0000-0000-000000000000",
              "urgency": "low"
            }
          ],
          "query": "tags.service:time_restrictions",
          "time_restriction": {
            "time_zone": "Europe/Paris",
            "restrictions": [
              {
                "end_day": "monday",
                "end_time": "17:00:00",
                "start_day": "monday",
                "start_time": "09:00:00"
              },
              {
                "end_day": "tuesday",
                "end_time": "17:00:00",
                "start_day": "tuesday",
                "start_time": "09:00:00"
              }
            ]
          }
        },
        {
          "actions": [
            {
              "type": "escalation_policy",
              "policy_id": "ab000000-0000-0000-0000-000000000000",
              "urgency": "low",
              "ack_timeout_minutes": 30,
              "support_hours": {
                "time_zone": "Europe/Paris",
                "restrictions": [
                  {
                    "end_day": "wednesday",
                    "end_time": "17:00:00",
                    "start_day": "wednesday",
                    "start_time": "09:00:00"
                  },
                  {
                    "end_day": "thursday",
                    "end_time": "17:00:00",
                    "start_day": "thursday",
                    "start_time": "09:00:00"
                  }
                ]
              }
            }
          ],
          "query": "tags.service:support_hours_and_acknowledgment_timeout"
        },
        {
          "policy_id": "ab000000-0000-0000-0000-000000000000",
          "query": "tags.service:legacy_policy_definition",
          "urgency": "low"
        },
        {
          "actions": [
            {
              "type": "escalation_policy",
              "policy_id": "ab000000-0000-0000-0000-000000000000",
              "urgency": "low"
            }
          ],
          "query": ""
        }
      ]
    },
    "id": "aeadc05e-98a8-11ec-ac2c-da7ad0900001",
    "type": "team_routing_rules"
  }
}
```

{% /tab %}

### Response

{% tab title="200" %}
OK
{% tab title="Model" %}
Represents a complete set of team routing rules, including data and optionally included related resources.

| Parent field     | Field                          | Type            | Description                                                                                                                                                                                                                                                                           |
| ---------------- | ------------------------------ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|                  | data                           | object          | Represents the top-level data object for team routing rules, containing the ID, relationships, and resource type.                                                                                                                                                                     |
| data             | id                             | string          | Specifies the unique identifier of this team routing rules record.                                                                                                                                                                                                                    |
| data             | relationships                  | object          | Specifies relationships for team routing rules, including rule references.                                                                                                                                                                                                            |
| relationships    | rules                          | object          | Holds references to a set of routing rules in a relationship.                                                                                                                                                                                                                         |
| rules            | data                           | [object]        | An array of references to the routing rules associated with this team.                                                                                                                                                                                                                |
| data             | id [*required*]           | string          | Specifies the unique identifier for the related routing rule.                                                                                                                                                                                                                         |
| data             | type [*required*]         | enum            | Indicates that the resource is of type 'team_routing_rules'. Allowed enum values: `team_routing_rules`                                                                                                                                                                                |
| data             | type [*required*]         | enum            | Team routing rules resource type. Allowed enum values: `team_routing_rules`                                                                                                                                                                                                           |
|                  | included                       | [ <oneOf>] | Provides related routing rules or other included resources.                                                                                                                                                                                                                           |
| included         | Option 1                       | object          | Represents a routing rule, including its attributes, relationships, and unique identifier.                                                                                                                                                                                            |
| Option 1         | attributes                     | object          | Defines the configurable attributes of a routing rule, such as actions, query, time restriction, and urgency.                                                                                                                                                                         |
| attributes       | actions                        | [ <oneOf>] | Specifies the list of actions to perform when the routing rule matches.                                                                                                                                                                                                               |
| actions          | Option 1                       | object          | Sends a message to a Slack channel.                                                                                                                                                                                                                                                   |
| Option 1         | channel [*required*]      | string          | The channel ID.                                                                                                                                                                                                                                                                       |
| Option 1         | type [*required*]         | enum            | Indicates that the action is a send Slack message action. Allowed enum values: `send_slack_message`                                                                                                                                                                                   |
| Option 1         | workspace [*required*]    | string          | The workspace ID.                                                                                                                                                                                                                                                                     |
| actions          | Option 2                       | object          | Sends a message to a Microsoft Teams channel.                                                                                                                                                                                                                                         |
| Option 2         | channel [*required*]      | string          | The channel ID.                                                                                                                                                                                                                                                                       |
| Option 2         | team [*required*]         | string          | The team ID.                                                                                                                                                                                                                                                                          |
| Option 2         | tenant [*required*]       | string          | The tenant ID.                                                                                                                                                                                                                                                                        |
| Option 2         | type [*required*]         | enum            | Indicates that the action is a send Microsoft Teams message action. Allowed enum values: `send_teams_message`                                                                                                                                                                         |
| actions          | Option 3                       | object          | Triggers a Workflow Automation.                                                                                                                                                                                                                                                       |
| Option 3         | handle [*required*]       | string          | The handle of the Workflow Automation to trigger.                                                                                                                                                                                                                                     |
| Option 3         | type [*required*]         | enum            | Indicates that the action triggers a Workflow Automation. Allowed enum values: `workflow`                                                                                                                                                                                             |
| actions          | Option 4                       | object          | Triggers an escalation policy.                                                                                                                                                                                                                                                        |
| Option 4         | ack_timeout_minutes            | int64           | The number of minutes before an acknowledged page is re-triggered.                                                                                                                                                                                                                    |
| Option 4         | policy_id [*required*]    | string          | The ID of the escalation policy to route to.                                                                                                                                                                                                                                          |
| Option 4         | support_hours                  | object          | Support hours during which the escalation policy will be executed. Outside of these hours, the escalation policy will be on hold and triggered once the next support hours window starts. This is mutually exclusive with the top-level `time_restriction` field on the routing rule. |
| support_hours    | restrictions                   | [object]        | The list of support hours time windows.                                                                                                                                                                                                                                               |
| restrictions     | end_day                        | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | end_time                       | string          | Specifies the ending time for this restriction.                                                                                                                                                                                                                                       |
| restrictions     | start_day                      | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | start_time                     | string          | Specifies the starting time for this restriction.                                                                                                                                                                                                                                     |
| support_hours    | time_zone [*required*]    | string          | The time zone in which the support hours are expressed.                                                                                                                                                                                                                               |
| Option 4         | type [*required*]         | enum            | Indicates that the action pages an escalation policy. This action can be set once per routing rule item, and is mutually exclusive with the top-level `policy_id` field on the routing rule. Allowed enum values: `escalation_policy`                                                 |
| Option 4         | urgency                        | enum            | Specifies the level of urgency for a routing rule (low, high, or dynamic). Allowed enum values: `low,high,dynamic`                                                                                                                                                                    |
| attributes       | query                          | string          | Defines the query or condition that triggers this routing rule.                                                                                                                                                                                                                       |
| attributes       | time_restriction               | object          | Time restrictions during which the routing rule is active. Outside of these hours, the rule does not match and routing continues to subsequent rules. This is mutually exclusive with the action-level `support_hours` field.                                                         |
| time_restriction | restrictions [*required*] | [object]        | Defines the list of time-based restrictions.                                                                                                                                                                                                                                          |
| restrictions     | end_day                        | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | end_time                       | string          | Specifies the ending time for this restriction.                                                                                                                                                                                                                                       |
| restrictions     | start_day                      | enum            | A day of the week. Allowed enum values: `monday,tuesday,wednesday,thursday,friday,saturday,sunday`                                                                                                                                                                                    |
| restrictions     | start_time                     | string          | Specifies the starting time for this restriction.                                                                                                                                                                                                                                     |
| time_restriction | time_zone [*required*]    | string          | Specifies the time zone applicable to the restrictions.                                                                                                                                                                                                                               |
| attributes       | urgency                        | enum            | Specifies the level of urgency for a routing rule (low, high, or dynamic). Allowed enum values: `low,high,dynamic`                                                                                                                                                                    |
| Option 1         | id                             | string          | Specifies the unique identifier of this routing rule.                                                                                                                                                                                                                                 |
| Option 1         | relationships                  | object          | Specifies relationships for a routing rule, linking to associated policy resources.                                                                                                                                                                                                   |
| relationships    | policy                         | object          | Defines the relationship that links a routing rule to a policy.                                                                                                                                                                                                                       |
| policy           | data                           | object          | Represents the policy data reference, containing the policy's ID and resource type.                                                                                                                                                                                                   |
| data             | id [*required*]           | string          | Specifies the unique identifier of the policy.                                                                                                                                                                                                                                        |
| data             | type [*required*]         | enum            | Indicates that the resource is of type 'policies'. Allowed enum values: `policies`                                                                                                                                                                                                    |
| Option 1         | type [*required*]         | enum            | Team routing rules resource type. Allowed enum values: `team_routing_rules`                                                                                                                                                                                                           |

{% /tab %}

{% tab title="Example" %}

```json
{
  "data": {
    "id": "27590dae-47be-4a7d-9abf-8f4e45124020",
    "relationships": {
      "rules": {
        "data": [
          {
            "id": "03aff2d6-6cbf-496c-997f-a857bbe9a94a",
            "type": "team_routing_rules"
          },
          {
            "id": "03aff2d6-6cbf-496c-997f-a857bbe9a94a",
            "type": "team_routing_rules"
          }
        ]
      }
    },
    "type": "team_routing_rules"
  },
  "included": [
    {
      "attributes": {
        "actions": null,
        "query": "tags.service:test",
        "time_restriction": {
          "restrictions": [
            {
              "end_day": "monday",
              "end_time": "17:00:00",
              "start_day": "monday",
              "start_time": "09:00:00"
            },
            {
              "end_day": "tuesday",
              "end_time": "17:00:00",
              "start_day": "tuesday",
              "start_time": "09:00:00"
            }
          ],
          "time_zone": ""
        },
        "urgency": "high"
      },
      "id": "03aff2d6-6cbf-496c-997f-a857bbe9a94a",
      "relationships": {
        "policy": {
          "data": null
        }
      },
      "type": "team_routing_rules"
    }
  ]
}
```

{% /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
# 
 \# Path parameters export team_id="27590dae-47be-4a7d-9abf-8f4e45124020" \# Curl command curl -X PUT "https://api.datadoghq.com/api/v2/on-call/teams/${team_id}/routing-rules" \
-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": {
      "rules": [
        {
          "actions": null,
          "policy_id": "",
          "query": "tags.service:test",
          "time_restriction": {
            "restrictions": [
              {
                "end_day": "monday",
                "end_time": "17:00:00",
                "start_day": "monday",
                "start_time": "09:00:00"
              },
              {
                "end_day": "tuesday",
                "end_time": "17:00:00",
                "start_day": "tuesday",
                "start_time": "09:00:00"
              }
            ],
            "time_zone": ""
          },
          "urgency": "high"
        },
        {
          "actions": [
            {
              "channel": "channel",
              "type": "send_slack_message",
              "workspace": "workspace"
            }
          ],
          "policy_id": "fad4eee1-13f5-40d8-886b-4e56d8d5d1c6",
          "query": "",
          "time_restriction": null,
          "urgency": "low"
        }
      ]
    },
    "id": "27590dae-47be-4a7d-9abf-8f4e45124020",
    "type": "team_routing_rules"
  }
}
EOF 
                        
##### 

```go
// Set On-Call team routing rules returns "OK" response

package main

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

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

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

	// there is a valid "escalation_policy" in the system
	EscalationPolicyDataID := os.Getenv("ESCALATION_POLICY_DATA_ID")

	body := datadogV2.TeamRoutingRulesRequest{
		Data: &datadogV2.TeamRoutingRulesRequestData{
			Attributes: &datadogV2.TeamRoutingRulesRequestDataAttributes{
				Rules: []datadogV2.TeamRoutingRulesRequestRule{
					{
						Actions: []datadogV2.RoutingRuleAction{
							datadogV2.RoutingRuleAction{
								SendSlackMessageAction: &datadogV2.SendSlackMessageAction{
									Channel:   "channel",
									Type:      datadogV2.SENDSLACKMESSAGEACTIONTYPE_SEND_SLACK_MESSAGE,
									Workspace: "workspace",
								}},
						},
						Query: datadog.PtrString("tags.service:test"),
						TimeRestriction: &datadogV2.TimeRestrictions{
							TimeZone: "Europe/Paris",
							Restrictions: []datadogV2.TimeRestriction{
								{
									EndDay:    datadogV2.WEEKDAY_MONDAY.Ptr(),
									EndTime:   datadog.PtrString("17:00:00"),
									StartDay:  datadogV2.WEEKDAY_MONDAY.Ptr(),
									StartTime: datadog.PtrString("09:00:00"),
								},
								{
									EndDay:    datadogV2.WEEKDAY_TUESDAY.Ptr(),
									EndTime:   datadog.PtrString("17:00:00"),
									StartDay:  datadogV2.WEEKDAY_TUESDAY.Ptr(),
									StartTime: datadog.PtrString("09:00:00"),
								},
							},
						},
					},
					{
						PolicyId: datadog.PtrString(EscalationPolicyDataID),
						Query:    datadog.PtrString(""),
						Urgency:  datadogV2.URGENCY_LOW.Ptr(),
					},
				},
			},
			Id:   datadog.PtrString(DdTeamDataID),
			Type: datadogV2.TEAMROUTINGRULESREQUESTDATATYPE_TEAM_ROUTING_RULES,
		},
	}
	ctx := datadog.NewDefaultContext(context.Background())
	configuration := datadog.NewConfiguration()
	apiClient := datadog.NewAPIClient(configuration)
	api := datadogV2.NewOnCallApi(apiClient)
	resp, r, err := api.SetOnCallTeamRoutingRules(ctx, DdTeamDataID, body, *datadogV2.NewSetOnCallTeamRoutingRulesOptionalParameters().WithInclude("rules"))

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

	responseContent, _ := json.MarshalIndent(resp, "", "  ")
	fmt.Fprintf(os.Stdout, "Response from `OnCallApi.SetOnCallTeamRoutingRules`:\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="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" go run "main.go"
##### 

```java
// Set On-Call team routing rules returns "OK" 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.SetOnCallTeamRoutingRulesOptionalParameters;
import com.datadog.api.client.v2.model.RoutingRuleAction;
import com.datadog.api.client.v2.model.SendSlackMessageAction;
import com.datadog.api.client.v2.model.SendSlackMessageActionType;
import com.datadog.api.client.v2.model.TeamRoutingRules;
import com.datadog.api.client.v2.model.TeamRoutingRulesRequest;
import com.datadog.api.client.v2.model.TeamRoutingRulesRequestData;
import com.datadog.api.client.v2.model.TeamRoutingRulesRequestDataAttributes;
import com.datadog.api.client.v2.model.TeamRoutingRulesRequestDataType;
import com.datadog.api.client.v2.model.TeamRoutingRulesRequestRule;
import com.datadog.api.client.v2.model.TimeRestriction;
import com.datadog.api.client.v2.model.TimeRestrictions;
import com.datadog.api.client.v2.model.Urgency;
import com.datadog.api.client.v2.model.Weekday;
import java.util.Arrays;
import java.util.Collections;

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

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

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

    TeamRoutingRulesRequest body =
        new TeamRoutingRulesRequest()
            .data(
                new TeamRoutingRulesRequestData()
                    .attributes(
                        new TeamRoutingRulesRequestDataAttributes()
                            .rules(
                                Arrays.asList(
                                    new TeamRoutingRulesRequestRule()
                                        .actions(
                                            Collections.singletonList(
                                                new RoutingRuleAction(
                                                    new SendSlackMessageAction()
                                                        .channel("channel")
                                                        .type(
                                                            SendSlackMessageActionType
                                                                .SEND_SLACK_MESSAGE)
                                                        .workspace("workspace"))))
                                        .query("tags.service:test")
                                        .timeRestriction(
                                            new TimeRestrictions()
                                                .timeZone("Europe/Paris")
                                                .restrictions(
                                                    Arrays.asList(
                                                        new TimeRestriction()
                                                            .endDay(Weekday.MONDAY)
                                                            .endTime("17:00:00")
                                                            .startDay(Weekday.MONDAY)
                                                            .startTime("09:00:00"),
                                                        new TimeRestriction()
                                                            .endDay(Weekday.TUESDAY)
                                                            .endTime("17:00:00")
                                                            .startDay(Weekday.TUESDAY)
                                                            .startTime("09:00:00")))),
                                    new TeamRoutingRulesRequestRule()
                                        .policyId(ESCALATION_POLICY_DATA_ID)
                                        .query("")
                                        .urgency(Urgency.LOW))))
                    .id(DD_TEAM_DATA_ID)
                    .type(TeamRoutingRulesRequestDataType.TEAM_ROUTING_RULES));

    try {
      TeamRoutingRules result =
          apiInstance.setOnCallTeamRoutingRules(
              DD_TEAM_DATA_ID,
              body,
              new SetOnCallTeamRoutingRulesOptionalParameters().include("rules"));
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling OnCallApi#setOnCallTeamRoutingRules");
      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="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" java "Example.java"
##### 

```python
"""
Set On-Call team routing rules returns "OK" 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.send_slack_message_action import SendSlackMessageAction
from datadog_api_client.v2.model.send_slack_message_action_type import SendSlackMessageActionType
from datadog_api_client.v2.model.team_routing_rules_request import TeamRoutingRulesRequest
from datadog_api_client.v2.model.team_routing_rules_request_data import TeamRoutingRulesRequestData
from datadog_api_client.v2.model.team_routing_rules_request_data_attributes import TeamRoutingRulesRequestDataAttributes
from datadog_api_client.v2.model.team_routing_rules_request_data_type import TeamRoutingRulesRequestDataType
from datadog_api_client.v2.model.team_routing_rules_request_rule import TeamRoutingRulesRequestRule
from datadog_api_client.v2.model.time_restriction import TimeRestriction
from datadog_api_client.v2.model.time_restrictions import TimeRestrictions
from datadog_api_client.v2.model.urgency import Urgency
from datadog_api_client.v2.model.weekday import Weekday

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

# there is a valid "escalation_policy" in the system
ESCALATION_POLICY_DATA_ID = environ["ESCALATION_POLICY_DATA_ID"]

body = TeamRoutingRulesRequest(
    data=TeamRoutingRulesRequestData(
        attributes=TeamRoutingRulesRequestDataAttributes(
            rules=[
                TeamRoutingRulesRequestRule(
                    actions=[
                        SendSlackMessageAction(
                            channel="channel",
                            type=SendSlackMessageActionType.SEND_SLACK_MESSAGE,
                            workspace="workspace",
                        ),
                    ],
                    query="tags.service:test",
                    time_restriction=TimeRestrictions(
                        time_zone="Europe/Paris",
                        restrictions=[
                            TimeRestriction(
                                end_day=Weekday.MONDAY,
                                end_time="17:00:00",
                                start_day=Weekday.MONDAY,
                                start_time="09:00:00",
                            ),
                            TimeRestriction(
                                end_day=Weekday.TUESDAY,
                                end_time="17:00:00",
                                start_day=Weekday.TUESDAY,
                                start_time="09:00:00",
                            ),
                        ],
                    ),
                ),
                TeamRoutingRulesRequestRule(
                    policy_id=ESCALATION_POLICY_DATA_ID,
                    query="",
                    urgency=Urgency.LOW,
                ),
            ],
        ),
        id=DD_TEAM_DATA_ID,
        type=TeamRoutingRulesRequestDataType.TEAM_ROUTING_RULES,
    ),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
    api_instance = OnCallApi(api_client)
    response = api_instance.set_on_call_team_routing_rules(team_id=DD_TEAM_DATA_ID, include="rules", 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="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" python3 "example.py"
##### 

```ruby
# Set On-Call team routing rules returns "OK" response

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

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

# there is a valid "escalation_policy" in the system
ESCALATION_POLICY_DATA_ID = ENV["ESCALATION_POLICY_DATA_ID"]

body = DatadogAPIClient::V2::TeamRoutingRulesRequest.new({
  data: DatadogAPIClient::V2::TeamRoutingRulesRequestData.new({
    attributes: DatadogAPIClient::V2::TeamRoutingRulesRequestDataAttributes.new({
      rules: [
        DatadogAPIClient::V2::TeamRoutingRulesRequestRule.new({
          actions: [
            DatadogAPIClient::V2::SendSlackMessageAction.new({
              channel: "channel",
              type: DatadogAPIClient::V2::SendSlackMessageActionType::SEND_SLACK_MESSAGE,
              workspace: "workspace",
            }),
          ],
          query: "tags.service:test",
          time_restriction: DatadogAPIClient::V2::TimeRestrictions.new({
            time_zone: "Europe/Paris",
            restrictions: [
              DatadogAPIClient::V2::TimeRestriction.new({
                end_day: DatadogAPIClient::V2::Weekday::MONDAY,
                end_time: "17:00:00",
                start_day: DatadogAPIClient::V2::Weekday::MONDAY,
                start_time: "09:00:00",
              }),
              DatadogAPIClient::V2::TimeRestriction.new({
                end_day: DatadogAPIClient::V2::Weekday::TUESDAY,
                end_time: "17:00:00",
                start_day: DatadogAPIClient::V2::Weekday::TUESDAY,
                start_time: "09:00:00",
              }),
            ],
          }),
        }),
        DatadogAPIClient::V2::TeamRoutingRulesRequestRule.new({
          policy_id: ESCALATION_POLICY_DATA_ID,
          query: "",
          urgency: DatadogAPIClient::V2::Urgency::LOW,
        }),
      ],
    }),
    id: DD_TEAM_DATA_ID,
    type: DatadogAPIClient::V2::TeamRoutingRulesRequestDataType::TEAM_ROUTING_RULES,
  }),
})
opts = {
  include: "rules",
}
p api_instance.set_on_call_team_routing_rules(DD_TEAM_DATA_ID, body, opts)
```

#### 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="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" rb "example.rb"
##### 

```rust
// Set On-Call team routing rules returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_on_call::OnCallAPI;
use datadog_api_client::datadogV2::api_on_call::SetOnCallTeamRoutingRulesOptionalParams;
use datadog_api_client::datadogV2::model::RoutingRuleAction;
use datadog_api_client::datadogV2::model::SendSlackMessageAction;
use datadog_api_client::datadogV2::model::SendSlackMessageActionType;
use datadog_api_client::datadogV2::model::TeamRoutingRulesRequest;
use datadog_api_client::datadogV2::model::TeamRoutingRulesRequestData;
use datadog_api_client::datadogV2::model::TeamRoutingRulesRequestDataAttributes;
use datadog_api_client::datadogV2::model::TeamRoutingRulesRequestDataType;
use datadog_api_client::datadogV2::model::TeamRoutingRulesRequestRule;
use datadog_api_client::datadogV2::model::TimeRestriction;
use datadog_api_client::datadogV2::model::TimeRestrictions;
use datadog_api_client::datadogV2::model::Urgency;
use datadog_api_client::datadogV2::model::Weekday;

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

    // there is a valid "escalation_policy" in the system
    let escalation_policy_data_id = std::env::var("ESCALATION_POLICY_DATA_ID").unwrap();
    let body = TeamRoutingRulesRequest::new().data(
        TeamRoutingRulesRequestData::new(TeamRoutingRulesRequestDataType::TEAM_ROUTING_RULES)
            .attributes(TeamRoutingRulesRequestDataAttributes::new().rules(vec![
                            TeamRoutingRulesRequestRule::new()
                                .actions(
                                    vec![
                                        RoutingRuleAction::SendSlackMessageAction(
                                            Box::new(
                                                SendSlackMessageAction::new(
                                                    "channel".to_string(),
                                                    SendSlackMessageActionType::SEND_SLACK_MESSAGE,
                                                    "workspace".to_string(),
                                                ),
                                            ),
                                        )
                                    ],
                                )
                                .query("tags.service:test".to_string())
                                .time_restriction(
                                    TimeRestrictions::new(
                                        vec![
                                            TimeRestriction::new()
                                                .end_day(Weekday::MONDAY)
                                                .end_time("17:00:00".to_string())
                                                .start_day(Weekday::MONDAY)
                                                .start_time("09:00:00".to_string()),
                                            TimeRestriction::new()
                                                .end_day(Weekday::TUESDAY)
                                                .end_time("17:00:00".to_string())
                                                .start_day(Weekday::TUESDAY)
                                                .start_time("09:00:00".to_string())
                                        ],
                                        "Europe/Paris".to_string(),
                                    ),
                                ),
                            TeamRoutingRulesRequestRule::new()
                                .policy_id(escalation_policy_data_id.clone())
                                .query("".to_string())
                                .urgency(Urgency::LOW)
                        ]))
            .id(dd_team_data_id.clone()),
    );
    let configuration = datadog::Configuration::new();
    let api = OnCallAPI::with_config(configuration);
    let resp = api
        .set_on_call_team_routing_rules(
            dd_team_data_id.clone(),
            body,
            SetOnCallTeamRoutingRulesOptionalParams::default().include("rules".to_string()),
        )
        .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="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" cargo run
##### 

```typescript
/**
 * Set On-Call team routing rules returns "OK" response
 */

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

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

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

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

const params: v2.OnCallApiSetOnCallTeamRoutingRulesRequest = {
  body: {
    data: {
      attributes: {
        rules: [
          {
            actions: [
              {
                channel: "channel",
                type: "send_slack_message",
                workspace: "workspace",
              },
            ],
            query: "tags.service:test",
            timeRestriction: {
              timeZone: "Europe/Paris",
              restrictions: [
                {
                  endDay: "monday",
                  endTime: "17:00:00",
                  startDay: "monday",
                  startTime: "09:00:00",
                },
                {
                  endDay: "tuesday",
                  endTime: "17:00:00",
                  startDay: "tuesday",
                  startTime: "09:00:00",
                },
              ],
            },
          },
          {
            policyId: ESCALATION_POLICY_DATA_ID,
            query: "",
            urgency: "low",
          },
        ],
      },
      id: DD_TEAM_DATA_ID,
      type: "team_routing_rules",
    },
  },
  teamId: DD_TEAM_DATA_ID,
  include: "rules",
};

apiInstance
  .setOnCallTeamRoutingRules(params)
  .then((data: v2.TeamRoutingRules) => {
    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="<DD_API_KEY>" DD_APP_KEY="<DD_APP_KEY>" tsc "example.ts"
{% /tab %}
