# Group and project members API

> 原文：[https://docs.gitlab.com/ee/api/members.html](https://docs.gitlab.com/ee/api/members.html)

*   [Valid access levels](#valid-access-levels)
*   [List all members of a group or project](#list-all-members-of-a-group-or-project)
*   [List all members of a group or project including inherited members](#list-all-members-of-a-group-or-project-including-inherited-members)
*   [Get a member of a group or project](#get-a-member-of-a-group-or-project)
*   [Get a member of a group or project, including inherited members](#get-a-member-of-a-group-or-project-including-inherited-members)
*   [Add a member to a group or project](#add-a-member-to-a-group-or-project)
*   [Edit a member of a group or project](#edit-a-member-of-a-group-or-project)
    *   [Set override flag for a member of a group](#set-override-flag-for-a-member-of-a-group)
    *   [Remove override for a member of a group](#remove-override-for-a-member-of-a-group)
*   [Remove a member from a group or project](#remove-a-member-from-a-group-or-project)
*   [Give a group access to a project](#give-a-group-access-to-a-project)

# Group and project members API[](#group-and-project-members-api "Permalink")

## Valid access levels[](#valid-access-levels "Permalink")

访问级别在`Gitlab::Access`模块中定义. 当前，这些级别被认可：

*   无法访问（ `0` ）
*   宾客（ `10` ）
*   记者（ `20` ）
*   显影剂（ `30` ）
*   养护者（ `40` ）
*   所有者（ `50` ）-仅对组有效

**注意：**由于[存在问题](https://gitlab.com/gitlab-org/gitlab/-/issues/219299) ，个人名称空间中的项目将不会显示所有者（ `50` ）所有者的权限.

## List all members of a group or project[](#list-all-members-of-a-group-or-project "Permalink")

获取可通过身份验证的用户查看的组或项目成员的列表. 仅返回直接成员，而不返回通过祖先组继承的成员.

此函数使用分页参数`page`和`per_page`来限制用户列表.

```
GET /groups/:id/members
GET /projects/:id/members 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `query` | string | no | 查询字符串以搜索成员 |
| `user_ids` | 整数数组 | no | 根据给定的用户 ID 过滤结果 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members" 
```

响应示例：

```
[  {  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  30,  "group_saml_identity":  null  },  {  "id":  2,  "username":  "john_doe",  "name":  "John Doe",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  30,  "email":  "john@example.com",  "group_saml_identity":  {  "extern_uid":"ABC-1234567890",  "provider":  "group_saml",  "saml_provider_id":  10  }  }  ] 
```

## List all members of a group or project including inherited members[](#list-all-members-of-a-group-or-project-including-inherited-members "Permalink")

获取可通过身份验证的用户查看的组或项目成员的列表，包括通过祖先组继承的成员. 当用户是项目/组和一个或多个祖先组的成员时，仅以项目`access_level` （如果存在）或用户所属项目组中第一个组的用户的`access_level`返回一次祖先链.

此函数使用分页参数`page`和`per_page`来限制用户列表.

```
GET /groups/:id/members/all
GET /projects/:id/members/all 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `query` | string | no | 查询字符串以搜索成员 |
| `user_ids` | 整数数组 | no | 根据给定的用户 ID 过滤结果 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/all"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/all" 
```

响应示例：

```
[  {  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  30,  "group_saml_identity":  null  },  {  "id":  2,  "username":  "john_doe",  "name":  "John Doe",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  30  "email":  "john@example.com",  "group_saml_identity":  {  "extern_uid":"ABC-1234567890",  "provider":  "group_saml",  "saml_provider_id":  10  }  },  {  "id":  3,  "username":  "foo_bar",  "name":  "Foo bar",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-11-22T14:13:35Z",  "access_level":  30,  "group_saml_identity":  null  }  ] 
```

## Get a member of a group or project[](#get-a-member-of-a-group-or-project "Permalink")

获取组或项目的成员. 仅返回直接成员，而不返回通过祖先组继承的成员.

```
GET /groups/:id/members/:user_id
GET /projects/:id/members/:user_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id" 
```

响应示例：

```
{  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "access_level":  30,  "expires_at":  null,  "group_saml_identity":  null  } 
```

## Get a member of a group or project, including inherited members[](#get-a-member-of-a-group-or-project-including-inherited-members "Permalink")

在 GitLab 12.4 中[引入](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/17744) .

获取组或项目的成员，包括通过祖先组继承的成员. 有关详细信息，请参见相应的[端点以列出所有继承的成员](#list-all-members-of-a-group-or-project-including-inherited-members) .

```
GET /groups/:id/members/all/:user_id
GET /projects/:id/members/all/:user_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/all/:user_id"
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/all/:user_id" 
```

响应示例：

```
{  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "access_level":  30,  "expires_at":  null,  "group_saml_identity":  null  } 
```

## Add a member to a group or project[](#add-a-member-to-a-group-or-project "Permalink")

将成员添加到组或项目.

```
POST /groups/:id/members
POST /projects/:id/members 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 新成员的用户标识 |
| `access_level` | integer | yes | 有效的访问级别 |
| `expires_at` | string | no | 日期格式为 YEAR-MONTH-DAY 的日期字符串 |

```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "user_id=1&access_level=30" "https://gitlab.example.com/api/v4/groups/:id/members"
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "user_id=1&access_level=30" "https://gitlab.example.com/api/v4/projects/:id/members" 
```

响应示例：

```
{  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  30,  "group_saml_identity":  null  } 
```

## Edit a member of a group or project[](#edit-a-member-of-a-group-or-project "Permalink")

更新组或项目的成员.

```
PUT /groups/:id/members/:user_id
PUT /projects/:id/members/:user_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |
| `access_level` | integer | yes | 有效的访问级别 |
| `expires_at` | string | no | 日期格式为 YEAR-MONTH-DAY 的日期字符串 |

```
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id?access_level=40"
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id?access_level=40" 
```

响应示例：

```
{  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  40,  "group_saml_identity":  null  } 
```

### Set override flag for a member of a group[](#set-override-flag-for-a-member-of-a-group "Permalink")

在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/4875) .

默认情况下，LDAP 组成员的访问级别设置为 LDAP 通过组同步指定的值. 您可以通过调用此端点来允许访问级别替代.

```
POST /groups/:id/members/:user_id/override 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 认证用户拥有[的组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id/override" 
```

响应示例：

```
{  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  40,  "override":  true  } 
```

### Remove override for a member of a group[](#remove-override-for-a-member-of-a-group "Permalink")

在 GitLab 13.0 中[引入](https://gitlab.com/gitlab-org/gitlab/-/issues/4875) .

将替代标志设置为 false，并允许 LDAP 组同步将访问级别重置为 LDAP 指定的值.

```
DELETE /groups/:id/members/:user_id/override 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 认证用户拥有[的组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |

```
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id/override" 
```

响应示例：

```
{  "id":  1,  "username":  "raymond_smith",  "name":  "Raymond Smith",  "state":  "active",  "avatar_url":  "https://www.gravatar.com/avatar/c2525a7f58ae3776070e44c106c48e15?s=80&d=identicon",  "web_url":  "http://192.168.1.8:3000/root",  "expires_at":  "2012-10-22T14:13:35Z",  "access_level":  40,  "override":  false  } 
```

## Remove a member from a group or project[](#remove-a-member-from-a-group-or-project "Permalink")

从组或项目中删除用户.

```
DELETE /groups/:id/members/:user_id
DELETE /projects/:id/members/:user_id 
```

| Attribute | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | integer/string | yes | 经过身份验证的用户拥有[的项目或组](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) |
| `user_id` | integer | yes | 成员的用户标识 |
| `unassign_issuables` | boolean | false | 标志，指示是否应从给定的组或项目内取消分配任何问题或合并请求的已删除成员 |

```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/groups/:id/members/:user_id"
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/:id/members/:user_id" 
```

## Give a group access to a project[](#give-a-group-access-to-a-project "Permalink")

See [share project with group](projects.html#share-project-with-group)