命名空间 API

  • Tier: 基础版,专业版,旗舰版
  • Offering: JihuLab.com,私有化部署

使用此 API 与命名空间交互,命名空间是一种用于组织用户和群组的特殊资源类别。有关更多信息,请参阅namespaces

此 API 使用分页来过滤结果。

列出所有命名空间#

History
    • top_level_only 在极狐GitLab 16.8 中引入。

列出当前用户可用的所有命名空间。如果用户是管理员,此端点返回实例中的所有命名空间。

plaintext
GET /namespaces
属性类型必需描述
searchstring仅返回名称或路径中包含指定值的命名空间。
owned_onlyboolean如果为 true,仅返回当前用户的命名空间。
top_level_onlyboolean在极狐GitLab 16.8 及更高版本中,如果为 true,仅返回顶级命名空间。

示例请求:

shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/namespaces"

示例响应:

json
1[ 2 { 3 "id": 1, 4 "name": "user1", 5 "path": "user1", 6 "kind": "user", 7 "full_path": "user1", 8 "parent_id": null, 9 "avatar_url": "https://secure.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 10 "web_url": "https://gitlab.example.com/user1", 11 "billable_members_count": 1, 12 "plan": "ultimate", 13 "end_date": null, 14 "trial_ends_on": null, 15 "trial": false, 16 "root_repository_size": 100, 17 "projects_count": 3 18 }, 19 { 20 "id": 2, 21 "name": "group1", 22 "path": "group1", 23 "kind": "group", 24 "full_path": "group1", 25 "parent_id": null, 26 "avatar_url": null, 27 "web_url": "https://gitlab.example.com/groups/group1", 28 "members_count_with_descendants": 2, 29 "billable_members_count": 2, 30 "plan": "ultimate", 31 "end_date": null, 32 "trial_ends_on": null, 33 "trial": false, 34 "root_repository_size": 100, 35 "projects_count": 3 36 }, 37 { 38 "id": 3, 39 "name": "bar", 40 "path": "bar", 41 "kind": "group", 42 "full_path": "foo/bar", 43 "parent_id": 9, 44 "avatar_url": null, 45 "web_url": "https://gitlab.example.com/groups/foo/bar", 46 "members_count_with_descendants": 5, 47 "billable_members_count": 5, 48 "end_date": null, 49 "trial_ends_on": null, 50 "trial": false, 51 "root_repository_size": 100, 52 "projects_count": 3 53 } 54]

对于群组所有者或 JihuLab.com 可能返回其他属性:

json
1[ 2 { 3 ... 4 "max_seats_used": 3, 5 "max_seats_used_changed_at":"2025-05-15T12:00:02.000Z", 6 "seats_in_use": 2, 7 "projects_count": 1, 8 "root_repository_size":0, 9 "members_count_with_descendants":26, 10 "plan": "free", 11 ... 12 } 13]

获取命名空间的详细信息#

获取指定命名空间的详细信息。

plaintext
GET /namespaces/:id
属性类型必需描述
idinteger/string命名空间的 ID 或URL 编码路径

示例请求:

shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/namespaces/2"

示例响应:

json
1{ 2 "id": 2, 3 "name": "group1", 4 "path": "group1", 5 "kind": "group", 6 "full_path": "group1", 7 "parent_id": null, 8 "avatar_url": null, 9 "web_url": "https://gitlab.example.com/groups/group1", 10 "members_count_with_descendants": 2, 11 "billable_members_count": 2, 12 "max_seats_used": 0, 13 "seats_in_use": 0, 14 "plan": "default", 15 "end_date": null, 16 "trial_ends_on": null, 17 "trial": false, 18 "root_repository_size": 100, 19 "projects_count": 3 20}

示例请求:

shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces/group1"

示例响应:

json
1{ 2 "id": 2, 3 "name": "group1", 4 "path": "group1", 5 "kind": "group", 6 "full_path": "group1", 7 "parent_id": null, 8 "avatar_url": null, 9 "web_url": "https://gitlab.example.com/groups/group1", 10 "members_count_with_descendants": 2, 11 "billable_members_count": 2, 12 "max_seats_used": 0, 13 "seats_in_use": 0, 14 "plan": "default", 15 "end_date": null, 16 "trial_ends_on": null, 17 "trial": false, 18 "root_repository_size": 100 19}

验证命名空间的可用性#

验证指定命名空间是否已存在。如果命名空间确实存在,端点建议替代名称。

plaintext
GET /namespaces/:namespace/exists
属性类型必需描述
namespacestring命名空间的路径。
parent_idinteger父命名空间的 ID。如果未指定,仅返回顶级命名空间。

示例请求:

shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/namespaces/my-group/exists?parent_id=1"

示例响应:

json
1{ 2 "exists": true, 3 "suggests": [ 4 "my-group1" 5 ] 6}