# Tài liệu tham khảo API Bảo trì

Source: https://instatus.com/help/vi/api/maintenances

## Lấy tất cả đợt bảo trì của trang

**Endpoint:**

```bash
GET /v2/:page_id/maintenances?page=:page&per_page=:per_page
```

- Số trang mặc định là 1.
- Giá trị per_page mặc định là 50 và tối đa là 100 mục mỗi trang.

**Phản hồi ví dụ:**

```json
[
  {
    "id": "ckf1fzzbt4nib0a352wwra6ff",
    "name": "Test maintenance",
    "status": "NOTSTARTEDYET",
    "start": "2020-09-13T18:38:58.326Z",
    "duration": 60,
    "notifyStart": true,
    "notifyEnd": true,
    "notifyEarly": true,
    "notifyMinutes": 60,
    "autoStart": true,
    "autoEnd": true,
    "updates": [
      {
        "id": "ckf1fzzpal97v0a322evc874c",
        "message": "We are planning for a scheduled maintenance during that time.",
        "messageHtml": "<p>We are planning for a scheduled maintenance during that time.</p>",
        "status": "NOTSTARTEDYET",
        "notify": true,
        "started": "2020-09-13T18:38:58.326Z",
        "ended": null,
        "updatedAt": "2020-09-13T18:38:58.326Z"
      }
    ]
  }
]
```
## Lấy một đợt bảo trì

**Endpoint:**

```bash
GET /v1/:page_id/maintenances/:maintenance_id
```

**Phản hồi ví dụ:**

```json
{
  "id": "ckf1fzzbt4nib0a352wwra6ff",
  "name": "Test maintenance",
  "status": "NOTSTARTEDYET",
  "start": "2020-09-13T18:38:58.326Z",
  "duration": 60,
  "notifyStart": true,
  "notifyEnd": true,
  "notifyEarly": true,
  "notifyMinutes": 60,
  "autoStart": true,
  "autoEnd": true,
  "updates": [
    {
      "id": "ckf1fzzpal97v0a322evc874c",
      "message": "We are planning for a scheduled maintenance during that time.",
      "messageHtml": "<p>We are planning for a scheduled maintenance during that time.</p>",
      "status": "NOTSTARTEDYET",
      "notify": true,
      "started": "2020-09-13T18:38:58.326Z",
      "ended": null,
      "duration": null,
      "createdAt": "2020-09-13T18:39:16.606Z"
    }
  ],
  "components": [
    {
      "id": "ckf01fvnxywz50a35nh1qzssm",
      "name": "Website",
      "status": "OPERATIONAL",
      "showUptime": true,
      "site": {
        "id": "ckf01fonve9i40a32oas5b0uw",
        "name": "Nasa",
        "subdomain": "nasa",
        "color": null,
        "logoUrl": null,
        "publicEmail": null
      }
    }
  ]
}
```

## Thêm một đợt bảo trì

**Endpoint:**

```bash
POST /v1/:page_id/maintenances
```

**Yêu cầu ví dụ:**

```json
{
  "name": "Test maintenance",
  "message": "We are scheduling a test maintenance",
  "components": ["ckf01fvnxywz50a35nh1qzssm"],
  "start": "2020-09-12 05:38:47.998",
  "end": "2020-09-12 06:38:47.998",
  "status": "NOTSTARTEDYET",
  "notify": true,
  "duration": 60,
  "notifyStart": true,
  "notifyEnd": true,
  "notifyEarly": true,
  "notifyMinutes": 60,
  "autoStart": true,
  "autoEnd": true,
  "statuses": [
    {
      "id": "ckf01fvnxywz50a35nh1qzssm",
      "status": "UNDERMAINTENANCE"
    }
  ],
  "translations": {
    "name": {
      "fr": "Entretien des tests"
    },
    "message": {
      "fr": "Nous planifions une maintenance test"
    }
  }
}
```
Các đợt bảo trì được mở rộng theo mặc định.

Nếu bạn muốn thu gọn đợt bảo trì rồi mở rộng nó vào một thời điểm mong muốn, bạn cần thêm và đặt `isCollapsed` thành `true` và `expandAt` thành thời điểm bạn muốn.

**Phản hồi ví dụ:**

```json
{
  "id": "ckf1g4evp4o5s0a35vozxnjv5",
  "name": "Test maintenance",
  "duration": null,
  "start": "2020-09-12T03:38:47.998Z",
  "end": "2020-09-12T04:38:47.998Z",
  "status": "NOTSTARTEDYET",
  "updates": [],
  "components": [
    {
      "id": "ckf01fvnxywz50a35nh1qzssm",
      "name": "Website",
      "status": "OPERATIONAL",
      "showUptime": true,
      "site": {
        "id": "ckf01fonve9i40a32oas5b0uw",
        "name": "Nasa",
        "subdomain": "nasa",
        "color": null,
        "logoUrl": null,
        "publicEmail": null
      }
    }
  ],
  "translations": {
    "name": {
      "fr": "Entretien des tests"
    },
    "message": {
      "fr": "Nous planifions une maintenance test"
    }
  }
}
```

## Cập nhật bảo trì

**Endpoint:**

```bash
PUT /v1/:page_id/maintenances/:maintenance_id
```

**Yêu cầu ví dụ:**

```json
{
  "name": "Test incident 2",
  "message": "We are scheduling a test maintenance",
  "components": ["ckf01fvnxywz50a35nh1qzssm"],
  "start": "2020-09-12 05:38:47.998",
  "end": "2020-09-12 06:38:47.998",
  "status": "NOTSTARTEDYET",
  "notify": true,
  "statuses": [
    {
      "id": "ckf01fvnxywz50a35nh1qzssm",
      "status": "UNDERMAINTENANCE"
    }
  ],
  "translations": {
    "name": {
      "fr": "Entretien des tests"
    },
    "message": {
      "fr": "Nous planifions une maintenance test"
    }
  }
}
```

**Phản hồi ví dụ:**

```json
{
  "id": "ckf1g4evp4o5s0a35vozxnjv5",
  "name": "Test maintenance 2",
  "status": "NOTSTARTEDYET",
  "start": "2020-09-12T03:38:47.998Z",
  "duration": null,
  "updates": [
    {
      "id": "ckf1g4ffi4o5y0a35rm76vuq9",
      "message": "We're currently investigating an issue with the Website",
      "messageHtml": "<p>We're currently investigating an issue with the Website</p>",
      "status": "NOTSTARTEDYET",
      "notify": true,
      "started": "2020-09-12T03:38:47.998Z",
      "ended": null,
      "duration": null,
      "createdAt": "2020-09-13T18:42:43.614Z"
    }
  ],
  "components": [
    {
      "id": "ckf01fvnxywz50a35nh1qzssm",
      "name": "Website",
      "status": "OPERATIONAL",
      "showUptime": true,
      "site": {
        "id": "ckf01fonve9i40a32oas5b0uw",
        "name": "Nasa",
        "subdomain": "nasa",
        "color": null,
        "logoUrl": null,
        "publicEmail": null
      }
    }
  ],
  "translations": {
    "name": {
      "fr": "Entretien des tests"
    },
    "message": {
      "fr": "Nous planifions une maintenance test"
    }
  }
}
```

## Xóa bảo trì

**Endpoint:**

```bash
DELETE /v1/:page_id/maintenances/:maintenance_id
```

**Phản hồi ví dụ:**

```json
{
  "id": "ckf1g4evp4o5s0a35vozxnjv5"
}
```
