> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fluz.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 移除授權使用者

透過停用其角色指派，從呼叫者的帳戶移除授權使用者。此 mutation 不會刪除該使用者——它會將呼叫者帳戶上的角色指派設為 `INACTIVE`，以撤銷其存取權。帳戶擁有者（`OWNER` 角色）無法透過此端點被移除。

目標帳戶一律由呼叫者的認證解析——Bearer 權杖使用權杖所屬的帳戶；Basic（API key）呼叫者使用應用程式已設定的營運者帳戶。`authUserId` 必須指向該帳戶上的角色指派；否則請求會被拒絕。

🔒 受限存取

此 mutation 需要 `MANAGE_SUBUSERS` 權限範圍。它同時支援 Bearer（使用者存取權杖）與 Basic（`<API_KEY>`）驗證。

```graphql theme={null}
mutation RemoveAuthorizedUser(
  $authUserId: UUID!
) {
  removeAuthorizedUser(
    authUserId: $authUserId
  ) {
    success
    authUserId
    status
    error {
      code
      message
    }
  }
}
```

<br />

### 參數

| 參數         | 型別   | 必填  | 說明                                                                       |
| :--------- | :--- | :-- | :----------------------------------------------------------------------- |
| authUserId | UUID | Yes | 要停用的授權使用者 ID（UAC 角色指派 ID）。可從 `authorizedUsers` 或 `addAuthorizedUser` 取得。 |

<br />

### 回應

#### 成功回應

```json theme={null}
{
  "data": {
    "removeAuthorizedUser": {
      "success": true,
      "authUserId": "8b2c1e0a-7d4f-4a9b-9c2d-1f3e4a5b6c7d",
      "status": "INACTIVE",
      "error": null
    }
  }
}
```

<br />

### 回應欄位

| 欄位           | 型別                  | 說明                                                 |
| :----------- | :------------------ | :------------------------------------------------- |
| `success`    | Boolean             | 若角色指派成功停用則為 `true`。                                |
| `authUserId` | UUID                | 已更新的授權使用者 ID（UAC 角色指派 ID）。                         |
| `status`     | UACRoleStatusType   | 角色指派的更新狀態。成功時為 `INACTIVE`。                         |
| `error`      | AuthorizedUserError | 若 `success` 為 false，則為包含 `code` 與 `message` 的錯誤物件。 |

<br />

<Note>
  此 mutation 會在回應資料中回傳錯誤，而非作為 GraphQL 錯誤。請務必檢查 `success` 欄位，且在 `success` 為 false 時處理 `error` 物件。
</Note>

### 範例請求

```curl theme={null}
curl -X POST https://transactional-graph.staging.fluzapp.com/api/v1/graphql \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your_access_token>" \
  -d '{
  "query": "mutation RemoveAuthorizedUser($authUserId: UUID!) { removeAuthorizedUser(authUserId: $authUserId) { success authUserId status error { code message } } }",
  "variables": {
    "authUserId": "8b2c1e0a-7d4f-4a9b-9c2d-1f3e4a5b6c7d"
  }
}'
```

```typescript theme={null}
const response = await fetch('https://transactional-graph.staging.fluzapp.com/api/v1/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${accessToken}`
  },
  body: JSON.stringify({
    query: `
      mutation RemoveAuthorizedUser(
        $authUserId: UUID!
      ) {
        removeAuthorizedUser(
          authUserId: $authUserId
        ) {
          success
          authUserId
          status
          error {
            code
            message
          }
        }
      }
    `,
    variables: {
      authUserId: "8b2c1e0a-7d4f-4a9b-9c2d-1f3e4a5b6c7d"
    }
  })
});

const data = await response.json();

if (data.data.removeAuthorizedUser.success) {
  console.log('Authorized user removed:', data.data.removeAuthorizedUser);
} else {
  console.error('Remove authorized user failed:', data.data.removeAuthorizedUser.error);
}
```

### 錯誤代碼

| 代碼          | 訊息                      | 說明                                                           |
| :---------- | :---------------------- | :----------------------------------------------------------- |
| `ARG-0002`  | 缺少必要的參數                 | 未提供 `authUserId`。                                            |
| `AUTH-0008` | 無效的使用者存取                | 無法從存取權杖或 API key 解析呼叫者，或是使用 Basic 驗證的應用程式未設定營運者帳戶。請驗證您的驗證憑證。 |
| `AUTH-0031` | 必須先由使用者授予所要求的權限範圍。      | 權杖缺少管理授權使用者所需的 `MANAGE_SUBUSERS` 權限範圍。                       |
| `AUTH-0034` | 在指定帳戶上找不到所提供授權使用者的角色指派。 | `authUserId` 並不存在於呼叫者的帳戶上，或該指派已為 `INACTIVE`。                 |
| `AUTH-0036` | 無法移除帳戶擁有者。              | 參照的角色指派持有 `OWNER` 角色，且無法透過此端點移除。                             |
| `AUTH-0037` | 無法管理授權使用者。請再試一次或聯絡支援。   | 在停用角色指派時發生一般性失敗。請重試或聯絡支援。                                    |

<br />
