# 升級政策 API 參考

Source: https://instatus.com/help/zh-tw/api/escalation-policies

## 欄位的可用值

**升級規則條件**

| 值 | 說明 |
| ------------------ | ---------------------------------------------------------- |
| `NOT_ACKNOWLEDGED` | 事件尚未被確認的狀況。 |

**升級動作類型**

| 值 | 說明 |
| ----------------------------- | ------------------------------------- |
| `NOTIFY_TEAM` | 通知特定團隊。 |
| `NOTIFY_WORKSPACE_MEMBER` | 通知特定工作區成員。 |
| `NOTIFY_CURRENT_ON_CALL_USER` | 通知目前的待命人員。 |
| `NOTIFY_NEXT_ON_CALL_USER` | 通知下一位待命人員。 |
| `NOTIFY_ALL_ON_CALL_MEMBERS` | 通知所有目前待命的成員。 |

## 取得升級政策

**端點：**

```bash
GET /:page_id/escalation-policies
```

**請求範例**

```bash
GET /1/escalation-policies
```

**回應範例**

```json
{
  "escalationPolicies": [
    {
      "id": "escalationPolicy123",
      "siteId": "site123",
      "name": "Primary Escalation Policy",
      "description": "This is the primary escalation policy for site123.",
      "rules": [
        {
          "id": "rule123",
          "escalationPolicyId": "escalationPolicy123",
          "order": 1,
          "condition": "NOT_ACKNOWLEDGED",
          "delayInMins": 5,
          "actions": [
            {
              "id": "action123",
              "ruleId": "rule123",
              "type": "NOTIFY_TEAM",
              "targetId": "team123",
              "createdAt": "2023-08-08T12:00:00Z",
              "updatedAt": "2023-08-08T12:00:00Z"
            },
            {
              "id": "action124",
              "ruleId": "rule123",
              "type": "NOTIFY_CURRENT_ON_CALL_USER",
              "targetId": null,
              "createdAt": "2023-08-08T12:01:00Z",
              "updatedAt": "2023-08-08T12:01:00Z"
            }
          ]
        },
        {
          "id": "rule456",
          "escalationPolicyId": "escalationPolicy123",
          "order": 2,
          "condition": "NOT_ACKNOWLEDGED",
          "delayInMins": 10,
          "actions": [
            {
              "id": "action125",
              "ruleId": "rule456",
              "type": "NOTIFY_NEXT_ON_CALL_USER",
              "targetId": null,
              "createdAt": "2023-08-08T12:10:00Z",
              "updatedAt": "2023-08-08T12:10:00Z"
            },
            {
              "id": "action126",
              "ruleId": "rule456",
              "type": "NOTIFY_WORKSPACE_MEMBER",
              "targetId": "member456",
              "createdAt": "2023-08-08T12:12:00Z",
              "updatedAt": "2023-08-08T12:12:00Z"
            }
          ]
        }
      ],
      "repeat": true,
      "repeatCount": 3,
      "repeatDelay": 15,
      "revertAcknowledgement": true,
      "autoResolveIncidentsAfterRepeat": false,
      "createdAt": "2023-08-08T12:00:00Z",
      "updatedAt": "2023-08-08T12:05:00Z"
    },
    {
      "id": "escalationPolicy456",
      "siteId": "site123",
      "name": "Secondary Escalation Policy",
      "description": "This is the secondary escalation policy for site123.",
      "rules": [],
      "repeat": false,
      "repeatCount": 0,
      "repeatDelay": 0,
      "revertAcknowledgement": false,
      "autoResolveIncidentsAfterRepeat": false,
      "createdAt": "2023-08-08T12:10:00Z",
      "updatedAt": "2023-08-08T12:10:00Z"
    }
  ]
}
```

## 建立升級政策

**端點：**

```bash
POST /escalation-policies
```

**請求範例**

```json
{
  "pageId": "12345",
  "name": "Critical Alerts Policy",
  "description": "Policy for handling critical alerts",
  "rules": [
    {
      "delayInMins": 5,
      "condition": "NOT_ACKNOWLEDGED",
      "actions": [
        {
          "targetId": "target-1",
          "type": "NOTIFY_WORKSPACE_MEMBER"
        },
        {
          "targetId": "target-2",
          "type": "NOTIFY_WORKSPACE_MEMBER"
        }
      ]
    }
  ],
  "repeat": true,
  "repeatDelay": 10,
  "repeatCount": 3,
  "autoResolveIncidentsAfterRepeat": false,
  "revertAcknowledgement": true
}
```

**回應範例**

```json
{
  "escalationPolicy": {
    "id": "new-escalation-policy-id",
    "pageId": "12345",
    "name": "Critical Alerts Policy",
    "description": "Policy for handling critical alerts",
    "rules": [
      {
        "delayInMins": 5,
        "condition": "NOT_ACKNOWLEDGED",
        "actions": [
          {
            "targetId": "target-1",
            "type": "NOTIFY_WORKSPACE_MEMBER"
          },
          {
            "targetId": "target-2",
            "type": "NOTIFY_WORKSPACE_MEMBER"
          }
        ]
      }
    ],
    "repeat": true,
    "repeatDelay": 10,
    "repeatCount": 3,
    "autoResolveIncidentsAfterRepeat": false,
    "revertAcknowledgement": true
  },
  "message": "Routing rule created successfully."
}
```

## 刪除升級政策

**端點：**

```bash
DELETE /escalation-policies/:id
```

**請求範例**

```bash
DELETE /escalation-policies/escalationPolicy123
```

**回應範例**

```json
{
  "message": "Escalation policy deleted successfully."
}
```

## 更新升級政策

**端點：**

```bash
PUT /escalation-policies/:id
```

**請求範例**

```json
{
  "pageId": "12345",
  "name": "Updated Critical Alerts Policy",
  "description": "Updated Policy for handling critical alerts",
  "rules": [
    {
      "delayInMins": 10,
      "condition": "NOT_ACKNOWLEDGED",
      "actions": [
        {
          "targetId": "target-1",
          "type": "NOTIFY_WORKSPACE_MEMBER"
        },
        {
          "targetId": "target-2",
          "type": "NOTIFY_WORKSPACE_MEMBER"
        }
      ]
    }
  ],
  "repeat": true,
  "repeatDelay": 10,
  "repeatCount": 3,
  "autoResolveIncidentsAfterRepeat": false,
  "revertAcknowledgement": true
}
```

**回應範例**

```json
{
  "escalationPolicy": {
    "pageId": "12345",
    "name": "Updated Critical Alerts Policy",
    "description": "Updated Policy for handling critical alerts",
    "rules": [
      {
        "delayInMins": 10,
        "condition": "NOT_ACKNOWLEDGED",
        "actions": [
          {
            "targetId": "target-1",
            "type": "NOTIFY_WORKSPACE_MEMBER"
          },
          {
            "targetId": "target-2",
            "type": "NOTIFY_WORKSPACE_MEMBER"
          }
        ]
      }
    ],
    "repeat": true,
    "repeatDelay": 10,
    "repeatCount": 3,
    "autoResolveIncidentsAfterRepeat": false,
    "revertAcknowledgement": true
  },
  "message": "Routing rule updated successfully."
}
```
