# Namespaces API > 原文:[https://docs.gitlab.com/ee/api/namespaces.html](https://docs.gitlab.com/ee/api/namespaces.html) * [List namespaces](#list-namespaces) * [Search for namespace](#search-for-namespace) * [Get namespace by ID](#get-namespace-by-id) # Namespaces API[](#namespaces-api "Permalink") 用户名和组名属于称为命名空间的特殊类别. 对于用户和组支持的 API 调用,请分别参阅[用户](users.html)和[组](groups.html)文档. [使用分页](README.html#pagination) . ## List namespaces[](#list-namespaces "Permalink") 获取已认证用户的名称空间列表. 如果用户是管理员,则会显示 GitLab 实例中所有名称空间的列表. ``` GET /namespaces ``` 请求示例: ``` curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/namespaces" ``` 响应示例: ``` [ { "id": 1, "name": "user1", "path": "user1", "kind": "user", "full_path": "user1" }, { "id": 2, "name": "group1", "path": "group1", "kind": "group", "full_path": "group1", "parent_id": null, "members_count_with_descendants": 2 }, { "id": 3, "name": "bar", "path": "bar", "kind": "group", "full_path": "foo/bar", "parent_id": 9, "members_count_with_descendants": 5 } ] ``` GitLab.com [Bronze 或更高版本](https://about.gitlab.com/pricing/#gitlab-com)上的用户可能还会看到与名称空间关联的`plan`参数: ``` [ { "id": 1, "name": "user1", "plan": "bronze", ... } ] ``` **注意:**仅向组维护者/所有者提供了`members_count_with_descendants`和`plan` . ## Search for namespace[](#search-for-namespace "Permalink") 获取与名称或路径中的字符串匹配的所有名称空间. ``` GET /namespaces?search=foobar ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `search` | string | no | 返回基于搜索条件授权用户查看的名称空间列表 | 请求示例: ``` curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/namespaces?search=twitter" ``` 响应示例: ``` [ { "id": 4, "name": "twitter", "path": "twitter", "kind": "group", "full_path": "twitter", "parent_id": null, "members_count_with_descendants": 2 } ] ``` ## Get namespace by ID[](#get-namespace-by-id "Permalink") 通过 ID 获取名称空间. ``` GET /namespaces/:id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | [名称空间的](README.html#namespaced-path-encoding) ID 或[URL 编码的路径](README.html#namespaced-path-encoding) | 请求示例: ``` curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/namespaces/2" ``` 响应示例: ``` { "id": 2, "name": "group1", "path": "group1", "kind": "group", "full_path": "group1", "parent_id": null, "members_count_with_descendants": 2 } ``` 请求示例: ``` curl --header "PRIVATE-TOKEN: " "https://gitlab.example.com/api/v4/namespaces/group1" ``` 响应示例: ``` { "id": 2, "name": "group1", "path": "group1", "kind": "group", "full_path": "group1", "parent_id": null, "members_count_with_descendants": 2 } ```