ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# Project Aliases API > 原文:[https://docs.gitlab.com/ee/api/project_aliases.html](https://docs.gitlab.com/ee/api/project_aliases.html) * [List all project aliases](#list-all-project-aliases) * [Get project alias’ details](#get-project-alias-details) * [Create a project alias](#create-a-project-alias) * [Delete a project alias](#delete-a-project-alias) # Project Aliases API[](#project-aliases-api-premium-only "Permalink") [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/3264) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.1. 所有方法都需要管理员授权. ## List all project aliases[](#list-all-project-aliases "Permalink") 获取所有项目别名的列表: ``` GET /project_aliases ``` ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases" ``` 响应示例: ``` [ { "id": 1, "project_id": 1, "name": "gitlab-foss" }, { "id": 2, "project_id": 2, "name": "gitlab" } ] ``` ## Get project alias’ details[](#get-project-alias-details "Permalink") 获取项目别名的详细信息: ``` GET /project_aliases/:name ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `name` | string | yes | 别名的名称 | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases/gitlab" ``` 响应示例: ``` { "id": 1, "project_id": 1, "name": "gitlab" } ``` ## Create a project alias[](#create-a-project-alias "Permalink") 为项目添加新的别名. 成功时回应 201,当验证错误时回应 400(例如别名已经存在): ``` POST /project_aliases ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `project_id` | integer/string | yes | 项目的 ID 或路径. | | `name` | string | yes | 别名的名称. 必须是唯一的. | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases" --form "project_id=1" --form "name=gitlab" ``` or ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases" --form "project_id=gitlab-org/gitlab" --form "name=gitlab" ``` 响应示例: ``` { "id": 1, "project_id": 1, "name": "gitlab" } ``` ## Delete a project alias[](#delete-a-project-alias "Permalink") 删除项目别名. 存在项目别名时以 204 响应,如果不存在则以 404 响应: ``` DELETE /project_aliases/:name ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `name` | string | yes | 别名的名称 | ``` curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/project_aliases/gitlab" ```