# 元件 API 參考

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

## 取得狀態頁的所有元件

**端點：**

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

- page 預設為 1。
- per_page 預設為 50，每頁最多 100 筆。

**回應範例：**

```json
[
  {
    "id": "ckf01fvnxywz60a35wdbn5gz5",
    "name": "App",
    "status": "OPERATIONAL",
    "uniqueEmail": "nasa-app-1nozrueut@automation.instatus.com",
    "description": "",
    "showUptime": true,
    "order": 0,
    "group": null
  },
  {
    "id": "ckf01fvnxywz50a35nh1qzssm",
    "name": "Website",
    "status": "OPERATIONAL",
    "description": "",
    "showUptime": true,
    "order": 0,
    "group": null,
    "uniqueEmail": "nasa-website-1nozrueut@automation.instatus.com"
  }
]
```

## 取得單一元件

**端點：**

```bash
GET /v2/:page_id/components/:component_id
```

**回應範例**

```json
{
  "id": "ckf01fvnxywz50a35nh1qzssm",
  "name": "Website",
  "description": "",
  "status": "OPERATIONAL",
  "uniqueEmail": "nasa-website-1nozrueut@automation.instatus.com",
  "showUptime": true,
  "order": 0,
  "group": null
}
```

## 建立元件

**端點：**

```bash
POST /v1/:page_id/components
```

**請求範例：**

```json
{
  "name": "Test component",
  "description": "Testing",
  "status": "OPERATIONAL",
  "order": 6,
  "showUptime": true,
  "grouped": false,
  "archived": false,
  "translations": {
    "name": {
      "fr": "Composant de test"
    },
    "description": {
      "fr": "En test"
    }
  }
}
```

**回應範例：**

```json
{
  "id": "ckf1d4f6a4aaf0a356vqg0rdm",
  "name": "Test component",
  "description": "Testing",
  "uniqueEmail": "nasa-test-component-oomaksikj@automation.instatus.com",
  "status": "OPERATIONAL",
  "showUptime": true,
  "order": 8,
  "group": null,
  "translations": {
    "name": {
      "fr": "Composant de test"
    },
    "description": {
      "fr": "En test"
    }
  }
}
```

如果你想把元件放在某個群組底下，可以把 `grouped` 設為 `true`，並把 `group` 設為目標群組的 `ID`。

## 更新元件

**端點：**

```bash
PUT /v2/:page_id/components/:component_id
```

**請求範例：**

```json
{
  "name": "Test component 4",
  "description": "Test test test",
  "status": "OPERATIONAL",
  "order": 6,
  "showUptime": true,
  "grouped": false,
  "archived": true,
  "translations": {
    "name": {
      "fr": "Composant de test 4"
    },
    "description": {
      "fr": "Test test test"
    }
  }
}
```

**回應範例：**

```json
{
  "id": "ckf1d4f6a4aaf0a356vqg0rdm",
  "name": "Test component 4",
  "uniqueEmail": "nasa-test-component-oomaksikj@automation.instatus.com",
  "status": "OPERATIONAL",
  "description": "Test test test",
  "showUptime": true,
  "order": 6,
  "group": null,
  "translations": {
    "name": {
      "fr": "Composant de test 4"
    },
    "description": {
      "fr": "Test test test"
    }
  }
}
```
如果你想更新元件所屬的群組，可以把 `grouped` 設為 `true`，並把 `groupId` 設為目標群組的 `ID`。

## 刪除元件

**端點：**

```bash
DELETE /v1/:page_id/components/:component_id
```

```json
{
  "id": "ckf1d4f6a4aaf0a356vqg0rdm"
}
```
