> For the complete documentation index, see [llms.txt](https://docs.ggwp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ggwp.com/chinese-simplified/shen-fen-yu-fang-wen-guan-li-iam/api-wen-dang-scim/yong-hu-api/geng-xin-yong-hu.md).

# 更新用户

## 更新用户

### 概述

该 `PATCH /Users/{id}` 端点用于对用户执行部分更新。

此实现支持 **有限的 PATCH 功能** 并主要用于更新用户的角色。

诸如 Okta 或 Microsoft Azure Active Directory 等身份提供商可能会在用户生命周期更新期间使用此端点。

***

### 支持的操作

仅支持以下操作：

* 更新用户角色

其他所有 PATCH 操作 **不受支持**.

***

### 端点

```bash
PATCH /Users/{id}
```

***

### 完整 URL

```bash
https://api.ggwp.com/scim/v2/Users/{id}
```

***

### 身份验证

```http
Authorization: Bearer <access_token>
```

***

## 请求正文

### 支持的模式

```json
{
  "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"]
}
```

***

### 示例请求（更新角色）

```json
{
  "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
  "Operations": [
    {
      "op": "replace",
      "path": "roles",
      "value": [
        {
          "value": "moderator"
        }
      ]
    }
  ]
}
```

***

## 支持的值

### 角色

* **类型：** `字符串`
* **允许的值：**
  * `admin`
  * `moderator`

***

## 响应

### 成功（200 OK）

```json
{
  "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
  "id": "c118d158-c11b-495b-ab88-f57c8ac473c0",
  "userName": "Temp_user_prod",
  "externalId": "ABC1900BE",
  "active": true,
  "name": {
    "givenName": "Temp",
    "familyName": "User"
  },
  "displayName": "Temp User",
  "emails": [
    {
      "value": "temp_user_us@example.com",
      "primary": true
    }
  ],
  "roles": [
    {
      "value": "admin"
    }
  ],
  "meta": {
    "resourceType": "User",
    "location": "https://api.ggwp.com/scim/v2/Users/c118d158-c11b-495b-ab88-f57c8ac473c0",
    "created": "2026-04-01T11:15:22Z",
    "lastModified": "2026-04-01T11:15:22Z"
  }
}
```

***

## 错误响应

### 400 错误请求（不支持的操作）

```json
{
  "schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"],
  "status": "400",
  "detail": "仅支持角色更新"
}
```

***

### 400 错误请求（无效的角色）

```json
{
  "schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"],
  "status": "400",
  "detail": "无效的角色值"
}
```

***

### 404 未找到

```json
{
  "schemas": ["urn:ietf:params:scim:api:messages:2.0:Error"],
  "status": "404",
  "detail": "未找到用户"
}
```

***

## 验证规则

* 仅 `替换` 操作受支持
* 仅 `path = "roles"` 受支持
* `值` 必须为以下之一：
  * `admin`
  * `moderator`
* 任何其他 PATCH 请求都将被拒绝
