# API Docs
> 原文:[https://docs.gitlab.com/ee/api/README.html](https://docs.gitlab.com/ee/api/README.html)
* [Available API resources](#available-api-resources)
* [SCIM](#scim-silver-only)
* [Road to GraphQL](#road-to-graphql)
* [Compatibility guidelines](#compatibility-guidelines)
* [Current status](#current-status)
* [Basic usage](#basic-usage)
* [Authentication](#authentication)
* [OAuth2 tokens](#oauth2-tokens)
* [Personal/project access tokens](#personalproject-access-tokens)
* [Session cookie](#session-cookie)
* [GitLab CI job token](#gitlab-ci-job-token)
* [Impersonation tokens](#impersonation-tokens)
* [Disable impersonation](#disable-impersonation)
* [Sudo](#sudo)
* [Status codes](#status-codes)
* [Pagination](#pagination)
* [Offset-based pagination](#offset-based-pagination)
* [Pagination Link header](#pagination-link-header)
* [Other pagination headers](#other-pagination-headers)
* [Keyset-based pagination](#keyset-based-pagination)
* [Path parameters](#path-parameters)
* [Namespaced path encoding](#namespaced-path-encoding)
* [File path, branches, and tags name encoding](#file-path-branches-and-tags-name-encoding)
* [Request Payload](#request-payload)
* [Encoding API parameters of `array` and `hash` types](#encoding-api-parameters-of-array-and-hash-types)
* [`array`](#array)
* [`hash`](#hash)
* [Array of hashes](#array-of-hashes)
* [`id` vs `iid`](#id-vs-iid)
* [Data validation and error reporting](#data-validation-and-error-reporting)
* [Unknown route](#unknown-route)
* [Encoding `+` in ISO 8601 dates](#encoding--in-iso-8601-dates)
* [Clients](#clients)
* [Rate limits](#rate-limits)
# API Docs[](#api-docs "Permalink")
通過簡單而強大的 API 自動化 GitLab.
主要的 GitLab API 是[REST](https://en.wikipedia.org/wiki/Representational_state_transfer) API. 因此,本節中的文檔假定您具有 REST 概念的知識.
## Available API resources[](#available-api-resources "Permalink")
有關可用資源及其端點的列表,請參閱[API 資源](api_resources.html) .
## SCIM[](#scim-silver-only "Permalink")
[GitLab.com Silver 和更高版本](https://about.gitlab.com/pricing/)提供了[SCIM API](scim.html) , [該](https://tools.ietf.org/html/rfc7644) [API](scim.html)實現[RFC7644 協議](https://tools.ietf.org/html/rfc7644)并提供`/Users`端點. 基本網址為: `/api/scim/v2/groups/:group_path/Users/` .
## Road to GraphQL[](#road-to-graphql "Permalink")
[GitLab](graphql/index.html)中提供了[GraphQL](graphql/index.html) ,它將允許棄用控制器特定的端點.
GraphQL 具有許多優點:
1. 我們避免維護兩個不同的 API.
2. API 的調用者只能請求他們需要的東西.
3. 默認情況下為版本.
它將與當前的 v4 REST API 共存. 如果我們有 v5 API,則這應該是 GraphQL 之上的兼容性層.
盡管 GraphQL 存在一些專利和許可問題,但通過 MIT 下的參考實現的重新許可以及 GraphQL 規范使用 OWF 許可證,這些問題已得到我們的滿意解決.
## Compatibility guidelines[](#compatibility-guidelines "Permalink")
HTTP API 使用單個數字進行版本控制,當前數字為 4.此數字與[SemVer](https://semver.org/)描述的主要版本號[相同](https://semver.org/) . 這意味著向后不兼容的更改將需要更改此版本號. 但是,次要版本不明確. 這可以實現穩定的 API 端點,但也意味著可以將新功能以相同的版本號添加到 API.
新功能和錯誤修復與新的 GitLab 一起發布,除附帶的修補程序和安全版本外,還于每月 22 日發布. 向后不兼容的更改(例如,端點刪除,參數刪除等)以及整個 API 版本的刪除與 GitLab 本身的主要版本一起進行. 兩個版本之間的所有棄用和更改都應在文檔中列出. 對于 v3 和 v4 之間的更改; 請閱讀[v3 至 v4 文檔](v3_to_v4.html)
### Current status[](#current-status "Permalink")
當前僅提供 API 版本 v4\. v3 版本已在[GitLab 11.0](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/36819)中刪除.
## Basic usage[](#basic-usage "Permalink")
API 請求應以`api`和 API 版本為前綴. API 版本在[`lib/api.rb`](https://gitlab.com/gitlab-org/gitlab/tree/master/lib/api/api.rb)定義. 例如,v4 API 的根位于`/api/v4` .
使用 cURL 的有效 API 請求的示例:
```
curl "https://gitlab.example.com/api/v4/projects"
```
該 API 使用 JSON 序列化數據. 您無需在 API URL 的末尾指定`.json` .
## Authentication[](#authentication "Permalink")
大多數 API 請求都需要身份驗證,或者僅在不提供身份驗證時才返回公共數據. 對于不需要的情況,將在文檔中針對每個端點進行提及. 例如, [`/projects/:id`端點](projects.html#get-single-project) .
使用 GitLab API 進行身份驗證的方法有幾種:
1. [OAuth2 tokens](#oauth2-tokens)
2. [Personal access tokens](../user/profile/personal_access_tokens.html)
3. [Project access tokens](../user/project/settings/project_access_tokens.html)
4. [Session cookie](#session-cookie)
5. [GitLab CI/CD job token](#gitlab-ci-job-token) **(僅特定端點)**
對于想要以特定用戶身份向 API 進行身份驗證的管理員,或者想要構建執行此操作的應用程序或腳本的管理員,可以使用以下兩種方法:
1. [Impersonation tokens](#impersonation-tokens)
2. [Sudo](#sudo)
如果身份驗證信息無效或被忽略,將返回一條錯誤消息,狀態碼為`401` :
```
{ "message": "401 Unauthorized" }
```
### OAuth2 tokens[](#oauth2-tokens "Permalink")
您可以通過在`access_token`參數或`Authorization`標頭中傳遞[OAuth2 令牌](oauth2.html)來對 API 進行身份驗證.
在參數中使用 OAuth2 令牌的示例:
```
curl "https://gitlab.example.com/api/v4/projects?access_token=OAUTH-TOKEN"
```
在標頭中使用 OAuth2 令牌的示例:
```
curl --header "Authorization: Bearer OAUTH-TOKEN" "https://gitlab.example.com/api/v4/projects"
```
閱讀有關[GitLab 作為 OAuth2 提供程序的](oauth2.html)更多信息.
### Personal/project access tokens[](#personalproject-access-tokens "Permalink")
Access tokens can be used to authenticate with the API by passing it in either the `private_token` parameter or the `Private-Token` header.
在參數中使用個人/項目訪問令牌的示例:
```
curl "https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>"
```
在標頭中使用個人/項目訪問令牌的示例:
```
curl --header "Private-Token: <your_access_token>" "https://gitlab.example.com/api/v4/projects"
```
您還可以將個人/項目訪問令牌與 OAuth 兼容標頭一起使用:
```
curl --header "Authorization: Bearer <your_access_token>" "https://gitlab.example.com/api/v4/projects"
```
### Session cookie[](#session-cookie "Permalink")
登錄主 GitLab 應用程序時,將設置`_gitlab_session` cookie. 如果存在,API 將使用此 cookie 進行身份驗證,但是當前不支持使用 API??生成新的會話 cookie.
這種身份驗證方法的主要用戶是 GitLab 本身的 Web 前端,它可以將 API 用作經過身份驗證的用戶來獲取其項目列表,例如,而無需顯式傳遞訪問令牌.
### GitLab CI job token[](#gitlab-ci-job-token "Permalink")
通過一些 API 端點,您可以使用[GitLab CI / CD 作業令牌](../user/project/new_ci_build_permissions_model.html#job-token)來對該 API 進行身份驗證:
* [Get job artifacts](jobs.html#get-job-artifacts)
* [Pipeline triggers](pipeline_triggers.html)
* [Release creation](releases/index.html#create-a-release)
### Impersonation tokens[](#impersonation-tokens "Permalink")
在 GitLab 9.0 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/9099) . 需要管理員權限.
模擬令牌是一種[個人訪問令牌](../user/profile/personal_access_tokens.html) ,只能由管理員為特定用戶創建. 如果您要構建以特定用戶身份通過??API 進行身份驗證的應用程序或腳本,則它們非常適合.
它們是直接使用用戶密碼或他們的個人訪問令牌之一以及使用[Sudo](#sudo)功能的替代方法,因為用戶(或管理員,對于 Sudo 而言)的密碼/令牌可能是未知的,或者可能隨時間變化.
有關更多信息,請參考[用戶 API](users.html#create-an-impersonation-token)文檔.
模擬令牌的使用與常規個人訪問令牌完全一樣,并且可以在`private_token`參數或`Private-Token`標頭中傳遞.
#### Disable impersonation[](#disable-impersonation "Permalink")
在 GitLab 11.6 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/40385) .
默認情況下,模擬是啟用的. 禁用模擬:
**對于所有安裝**
1. Edit `/etc/gitlab/gitlab.rb`:
```
gitlab_rails['impersonation_enabled'] = false
```
2. 保存文件并[重新配置](../administration/restart_gitlab.html#omnibus-gitlab-reconfigure) GitLab,以使更改生效.
要重新啟用模擬,請刪除此配置并重新配置 GitLab.
**對于源安裝**
1. Edit `config/gitlab.yml`:
```
gitlab:
impersonation_enabled: false
```
2. 保存文件并[重新啟動](../administration/restart_gitlab.html#installations-from-source) GitLab,以使更改生效.
要重新啟用模擬,請刪除此配置并重新啟動 GitLab.
### Sudo[](#sudo "Permalink")
**注意:**僅對[管理員](../user/permissions.html)可用.
如果已通過具有`sudo`范圍的 OAuth 或 Personal Access Token 作為管理員進行身份驗證,則所有 API 請求都支持執行 API 調用,就好像您是另一個用戶一樣.
您需要通過查詢字符串或帶有您要執行操作的用戶的 ID /用戶名的標頭傳遞`sudo`參數. 如果作為標題傳遞,則標題名稱必須為`Sudo` .
**注意:**用戶名不區分大小寫.
如果提供了非管理訪問令牌,將返回錯誤消息,狀態碼為`403` :
```
{ "message": "403 Forbidden - Must be admin to use sudo" }
```
如果提供了沒有`sudo`范圍的訪問令牌,則將返回錯誤消息,狀態碼為`403` :
```
{ "error": "insufficient_scope", "error_description": "The request requires higher privileges than provided by the access token.", "scope": "sudo" }
```
如果找不到 sudo 用戶 ID 或用戶名,將返回錯誤消息,狀態碼為`404` :
```
{ "message": "404 User with ID or username '123' Not Found" }
```
有效的 API 調用和使用 cURL 和 sudo request(提供用戶名)的請求的示例:
```
GET /projects?private_token=<your_access_token>&sudo=username
```
```
curl --header "Private-Token: <your_access_token>" --header "Sudo: username" "https://gitlab.example.com/api/v4/projects"
```
提供 ID 的有效 API 調用和使用 cURL 和 sudo request 的請求的示例:
```
GET /projects?private_token=<your_access_token>&sudo=23
```
```
curl --header "Private-Token: <your_access_token>" --header "Sudo: 23" "https://gitlab.example.com/api/v4/projects"
```
## Status codes[](#status-codes "Permalink")
該 API 旨在根據上下文和操作返回不同的狀態代碼. 這樣,如果請求導致錯誤,則調用者可以洞悉出了什么問題.
下表概述了 API 函數的一般行為.
| 請求類型 | Description |
| --- | --- |
| `GET` | 訪問一個或多個資源,并將結果作為 JSON 返回. |
| `POST` | 如果成功創建資源,則返回`201 Created` ,然后將新創建的資源作為 JSON 返回. |
| `GET` / `PUT` | 如果成功訪問或修改了資源,則返回`200 OK` . (修改后的)結果作為 JSON 返回. |
| `DELETE` | 如果資源已成功刪除,則返回`204 No Content` . |
下表顯示了 API 請求的可能返回碼.
| 返回值 | Description |
| --- | --- |
| `200 OK` | `GET` , `PUT`或`DELETE`請求成功,資源本身作為 JSON 返回. |
| `204 No Content` | 服務器已成功滿足請求,并且響應有效載荷主體中沒有其他要發送的內容. |
| `201 Created` | `POST`請求成功,資源作為 JSON 返回. |
| `304 Not Modified` | 指示自上次請求以來尚未修改資源. |
| `400 Bad Request` | API 請求的必需屬性丟失,例如,未提供問題標題. |
| `401 Unauthorized` | 用戶未通過身份驗證,有效的[用戶令牌](#authentication)是必需的. |
| `403 Forbidden` | 不允許該請求,例如,不允許用戶刪除項目. |
| `404 Not Found` | 無法訪問資源,例如,找不到資源的 ID. |
| `405 Method Not Allowed` | The request is not supported. |
| `409 Conflict` | 已經存在沖突的資源,例如,使用已經存在的名稱創建項目. |
| `412` | 表示請求被拒絕. `If-Unmodified-Since`嘗試刪除資源時提供了`If-Unmodified-Since`標頭,則可能會發生這種情況. |
| `422 Unprocessable` | 無法處理該實體. |
| `500 Server Error` | 在處理請求時,服務器端出了點問題. |
## Pagination[](#pagination "Permalink")
我們支持兩種分頁方法:
* 基于偏移的分頁. 這是默認方法,并且在所有端點上都可用.
* 基于鍵集的分頁. 已添加到選定的端點,但會[逐步推出](https://gitlab.com/groups/gitlab-org/-/epics/2039) .
對于大型集合,出于性能原因,我們建議鍵集分頁(如果有)而不是偏移分頁.
### Offset-based pagination[](#offset-based-pagination "Permalink")
有時,返回的結果將跨越許多頁面. 列出資源時,可以傳遞以下參數:
| Parameter | Description |
| --- | --- |
| `page` | 頁碼(默認: `1` ) |
| `per_page` | 每頁要列出的項目數(默認: `20` ,最大: `100` ) |
在下面的示例中,我們每頁列出 50 個[名稱空間](namespaces.html) .
```
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/namespaces?per_page=50"
```
#### Pagination Link header[](#pagination-link-header "Permalink")
[鏈接頭](https://www.w3.org/wiki/LinkHeader)隨每個響應一起發送回去. 它們的`rel`設置為 prev / next / first / last 并包含相關的 URL. 請使用這些鏈接,而不是生成自己的 URL.
在下面的卷曲的例子,我們限制輸出到每頁 3 項( `per_page=3` ),我們要求的第二頁( `page=2`的) [評論](notes.html)與 ID 問題的`8`屬于與 ID 項目`8` :
```
curl --head --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/8/issues/8/notes?per_page=3&page=2"
```
響應將是:
```
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 1103
Content-Type: application/json
Date: Mon, 18 Jan 2016 09:43:18 GMT
Link: <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=1&per_page=3>; rel="prev", <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=3&per_page=3>; rel="next", <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=1&per_page=3>; rel="first", <https://gitlab.example.com/api/v4/projects/8/issues/8/notes?page=3&per_page=3>; rel="last"
Status: 200 OK
Vary: Origin
X-Next-Page: 3
X-Page: 2
X-Per-Page: 3
X-Prev-Page: 1
X-Request-Id: 732ad4ee-9870-4866-a199-a9db0cde3c86
X-Runtime: 0.108688
X-Total: 8
X-Total-Pages: 3
```
#### Other pagination headers[](#other-pagination-headers "Permalink")
其他分頁標題也會發送回.
| Header | Description |
| --- | --- |
| `X-Total` | 項目總數 |
| `X-Total-Pages` | 總頁數 |
| `X-Per-Page` | 每頁的項目數 |
| `X-Page` | 當前頁面的索引(從 1 開始) |
| `X-Next-Page` | 下一頁的索引 |
| `X-Prev-Page` | 前一頁的索引 |
**注意:**由于性能原因,自[GitLab 11.8 起](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23931)并**在`api_kaminari_count_with_limit` [功能標志](../development/feature_flags/index.html)后面** ,如果資源數量大于 10,000,則`X-Total`和`X-Total-Pages`標頭以及`rel="last"` `Link`將不存在響應頭.
### Keyset-based pagination[](#keyset-based-pagination "Permalink")
鍵集分頁可以更有效地檢索頁面,并且與基于偏移的分頁相比,運行時與集合的大小無關.
此方法由以下參數控制:
| Parameter | Description |
| --- | --- |
| `pagination` | `keyset` (啟用鍵集分頁) |
| `per_page` | 每頁要列出的項目數(默認: `20` ,最大: `100` ) |
在下面的示例中,我們每頁列出 50 [個項目](projects.html) ,并按`id`升序排列.
```
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc"
```
響應頭包括指向下一頁的鏈接. 例如:
```
HTTP/1.1 200 OK
...
Links: <https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
Link: <https://gitlab.example.com/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
Status: 200 OK
...
```
**棄用:** `Links`標題將在 GitLab 14.0 中刪除,以符合[W3C `Link`規范](https://www.w3.org/wiki/LinkHeader)
指向下一頁的鏈接包含一個附加過濾器`id_after=42` ,該過濾器不包括我們已經檢索到的記錄. 請注意,過濾器的類型取決于所使用的`order_by`選項,我們可能有多個過濾器.
當到達集合的末尾并且沒有其他要檢索的記錄時,將沒有`Links`頭,并且結果數組為空.
我們建議僅使用給定的鏈接來檢索下一頁,而不要構建自己的 URL. 除了顯示的標題外,我們不公開其他分頁標題.
僅針對所選資源和訂購選項支持基于鍵集的分頁:
| Resource | Order |
| --- | --- |
| [Projects](projects.html) | `order_by=id` only |
## Path parameters[](#path-parameters "Permalink")
如果端點具有路徑參數,則文檔將在它們前面加上冒號.
例如:
```
DELETE /projects/:id/share/:group_id
```
`:id`路徑參數需要替換為項目 ID,而`:group_id`需要替換為組的 ID. 冒號`:`不應包含在內.
因此,對 ID 為`5` ,組 ID 為`17`的項目的 cURL 調用為:
```
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/share/17"
```
**注意:**必須遵循要求進行 URL 編碼的路徑參數. 如果不是,它將與 API 端點不匹配并以 404 進行響應.如果 API 前面有某些內容(例如 Apache),請確保它不會對 URL 編碼的路徑參數進行解碼.
## Namespaced path encoding[](#namespaced-path-encoding "Permalink")
如果使用命名空間的 API 調用,請確保`NAMESPACE/PROJECT_PATH`是 URL 編碼的.
例如, `/`由`/`表示:
```
GET /api/v4/projects/diaspora%2Fdiaspora
```
**注意:**項目的**路徑**不必與**名稱**相同. 可以在項目的 URL 或項目設置中的**常規>高級>更改路徑**下找到項目的**路徑** .
## File path, branches, and tags name encoding[](#file-path-branches-and-tags-name-encoding "Permalink")
如果文件路徑,分支或標記包含`/` ,請確保其經過 URL 編碼.
例如, `/`由`/`表示:
```
GET /api/v4/projects/1/repository/files/src%2FREADME.md?ref=master
GET /api/v4/projects/1/branches/my%2Fbranch/commits
GET /api/v4/projects/1/repository/tags/my%2Ftag
```
## Request Payload[](#request-payload "Permalink")
API 請求可以使用作為[查詢字符串](https://en.wikipedia.org/wiki/Query_string)或[有效載荷主體](https://tools.ietf.org/html/draft-ietf-httpbis-p3-payload-14#section-3.2)發送的參數. GET 請求通常發送查詢字符串,而 PUT / POST 請求通常發送有效內容正文:
* 請求參數:
```
curl --request POST "https://gitlab/api/v4/projects?name=<example-name>&description=<example-description>"
```
* 請求有效載荷(JSON):
```
curl --request POST --header "Content-Type: application/json" --data '{"name":"<example-name>", "description":"<example-description"}' "https://gitlab/api/v4/projects"
```
URL 編碼的查詢字符串具有長度限制. 請求太大將導致`414 Request-URI Too Large`錯誤消息. 這可以通過使用有效載荷主體來解決.
## Encoding API parameters of `array` and `hash` types[](#encoding-api-parameters-of-array-and-hash-types "Permalink")
我們可以使用`array`和`hash`類型參數調用 API,如下所示:
### `array`[](#array "Permalink")
`import_sources`是`array`類型的參數:
```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
-d "import_sources[]=github" \
-d "import_sources[]=bitbucket" \
https://gitlab.example.com/api/v4/some_endpoint
```
### `hash`[](#hash "Permalink")
`override_params`是`hash`類型的參數:
```
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
--form "namespace=email" \
--form "path=impapi" \
--form "file=@/path/to/somefile.txt"
--form "override_params[visibility]=private" \
--form "override_params[some_other_param]=some_value" \
https://gitlab.example.com/api/v4/projects/import
```
### Array of hashes[](#array-of-hashes "Permalink")
`variables`是包含哈希鍵/值對`[{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }]` `array`類型的參數:
```
curl --globoff --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/projects/169/pipeline?ref=master&variables[][key]=VAR1&variables[][value]=hello&variables[][key]=VAR2&variables[][value]=world"
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{ "ref": "master", "variables": [ {"key": "VAR1", "value": "hello"}, {"key": "VAR2", "value": "world"} ] }' \
"https://gitlab.example.com/api/v4/projects/169/pipeline"
```
## `id` vs `iid`[](#id-vs-iid "Permalink")
Some resources have two similarly-named fields. For example, [issues](issues.html), [merge requests](merge_requests.html), and [project milestones](merge_requests.html). The fields are:
* `id` :在所有項目中唯一的 ID.
* `iid` :在單個項目范圍內唯一的附加內部 ID.
**注意:** `iid`顯示在 Web UI 中.
如果資源具有`iid`字段和`id`字段,則通常使用`iid`字段代替`id`來獲取資源.
例如,假設一個`id: 42`的項目有一個`id: 46`和`iid: 5` . 在這種情況下:
* 檢索問題的有效 API 調用是`GET /projects/42/issues/5`
* 檢索問題的無效 API 調用是`GET /projects/42/issues/46` .
**注意:**并非所有具有`iid`字段的資源都由`iid`獲取. 有關使用哪個字段的指導,請參閱特定資源的文檔.
## Data validation and error reporting[](#data-validation-and-error-reporting "Permalink")
使用 API??時,您可能會遇到驗證錯誤,在這種情況下,API 會以 HTTP `400`狀態進行回答.
這種錯誤在兩種情況下出現:
* API 請求的必需屬性丟失,例如,未給出問題標題
* 屬性未通過驗證,例如,用戶簡歷太長
當缺少屬性時,您將獲得類似以下內容的信息:
```
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"message":"400 (Bad request) \"title\" not given"
}
```
發生驗證錯誤時,錯誤消息將有所不同. 它們將包含驗證錯誤的所有詳細信息:
```
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"message": {
"bio": [
"is too long (maximum is 255 characters)"
]
}
}
```
這使錯誤消息更加機器可讀. 格式可以描述如下:
```
{ "message": { "<property-name>": [ "<error-message>", "<error-message>", ... ], "<embed-entity>": { "<property-name>": [ "<error-message>", "<error-message>", ... ], } } }
```
## Unknown route[](#unknown-route "Permalink")
當您嘗試訪問不存在的 API URL 時,您將收到 404 Not Found.
```
HTTP/1.1 404 Not Found
Content-Type: application/json
{
"error": "404 Not Found"
}
```
## Encoding `+` in ISO 8601 dates[](#encoding--in-iso-8601-dates "Permalink")
如果需要在查詢參數中包含`+` ,則由于[W3 建議](http://www.w3.org/Addressing/URL/4_URI_Recommentations.html)會將`+`解釋為空格,因此可能需要使用`+`來代替. 例如,在一個 ISO 8601 日期中,您可能希望以"山區標準時間"傳遞時間,例如:
```
2017-10-17T23:11:13.000+05:30
```
The correct encoding for the query parameter would be:
```
2017-10-17T23:11:13.000%2B05:30
```
## Clients[](#clients "Permalink")
大多數流行的編程語言都有許多非官方的 GitLab API 客戶端. 訪問[GitLab 網站](https://about.gitlab.com/partners/#api-clients)以獲取完整列表.
## Rate limits[](#rate-limits "Permalink")
有關速率限制設置的管理員文檔,請參閱[速率限制](../security/rate_limits.html) . 要查找 GitLab.com 專門使用的設置,請參閱[GitLab.com 特定的速率限制](../user/gitlab_com/index.html#gitlabcom-specific-rate-limits) .
- GitLab Docs
- Installation
- Requirements
- GitLab cloud native Helm Chart
- Install GitLab with Docker
- Installation from source
- Install GitLab on Microsoft Azure
- Installing GitLab on Google Cloud Platform
- Installing GitLab on Amazon Web Services (AWS)
- Analytics
- Code Review Analytics
- Productivity Analytics
- Value Stream Analytics
- Kubernetes clusters
- Adding and removing Kubernetes clusters
- Adding EKS clusters
- Adding GKE clusters
- Group-level Kubernetes clusters
- Instance-level Kubernetes clusters
- Canary Deployments
- Cluster Environments
- Deploy Boards
- GitLab Managed Apps
- Crossplane configuration
- Cluster management project (alpha)
- Kubernetes Logs
- Runbooks
- Serverless
- Deploying AWS Lambda function using GitLab CI/CD
- Securing your deployed applications
- Groups
- Contribution Analytics
- Custom group-level project templates
- Epics
- Manage epics
- Group Import/Export
- Insights
- Issues Analytics
- Iterations
- Public access
- SAML SSO for GitLab.com groups
- SCIM provisioning using SAML SSO for GitLab.com groups
- Subgroups
- Roadmap
- Projects
- GitLab Secure
- Security Configuration
- Container Scanning
- Dependency Scanning
- Dependency List
- Static Application Security Testing (SAST)
- Secret Detection
- Dynamic Application Security Testing (DAST)
- GitLab Security Dashboard
- Offline environments
- Standalone Vulnerability pages
- Security scanner integration
- Badges
- Bulk editing issues and merge requests at the project level
- Code Owners
- Compliance
- License Compliance
- Compliance Dashboard
- Create a project
- Description templates
- Deploy Keys
- Deploy Tokens
- File finder
- Project integrations
- Integrations
- Atlassian Bamboo CI Service
- Bugzilla Service
- Custom Issue Tracker service
- Discord Notifications service
- Enabling emails on push
- GitHub project integration
- Hangouts Chat service
- Atlassian HipChat
- Irker IRC Gateway
- GitLab Jira integration
- Mattermost Notifications Service
- Mattermost slash commands
- Microsoft Teams service
- Mock CI Service
- Prometheus integration
- Redmine Service
- Slack Notifications Service
- Slack slash commands
- GitLab Slack application
- Webhooks
- YouTrack Service
- Insights
- Issues
- Crosslinking Issues
- Design Management
- Confidential issues
- Due dates
- Issue Boards
- Issue Data and Actions
- Labels
- Managing issues
- Milestones
- Multiple Assignees for Issues
- Related issues
- Service Desk
- Sorting and ordering issue lists
- Issue weight
- Associate a Zoom meeting with an issue
- Merge requests
- Allow collaboration on merge requests across forks
- Merge Request Approvals
- Browser Performance Testing
- How to create a merge request
- Cherry-pick changes
- Code Quality
- Load Performance Testing
- Merge Request dependencies
- Fast-forward merge requests
- Merge when pipeline succeeds
- Merge request conflict resolution
- Reverting changes
- Reviewing and managing merge requests
- Squash and merge
- Merge requests versions
- Draft merge requests
- Members of a project
- Migrating projects to a GitLab instance
- Import your project from Bitbucket Cloud to GitLab
- Import your project from Bitbucket Server to GitLab
- Migrating from ClearCase
- Migrating from CVS
- Import your project from FogBugz to GitLab
- Gemnasium
- Import your project from GitHub to GitLab
- Project importing from GitLab.com to your private GitLab instance
- Import your project from Gitea to GitLab
- Import your Jira project issues to GitLab
- Migrating from Perforce Helix
- Import Phabricator tasks into a GitLab project
- Import multiple repositories by uploading a manifest file
- Import project from repo by URL
- Migrating from SVN to GitLab
- Migrating from TFVC to Git
- Push Options
- Releases
- Repository
- Branches
- Git Attributes
- File Locking
- Git file blame
- Git file history
- Repository mirroring
- Protected branches
- Protected tags
- Push Rules
- Reduce repository size
- Signing commits with GPG
- Syntax Highlighting
- GitLab Web Editor
- Web IDE
- Requirements Management
- Project settings
- Project import/export
- Project access tokens (Alpha)
- Share Projects with other Groups
- Snippets
- Static Site Editor
- Wiki
- Project operations
- Monitor metrics for your CI/CD environment
- Set up alerts for Prometheus metrics
- Embedding metric charts within GitLab-flavored Markdown
- Embedding Grafana charts
- Using the Metrics Dashboard
- Dashboard YAML properties
- Metrics dashboard settings
- Panel types for dashboards
- Using Variables
- Templating variables for metrics dashboards
- Prometheus Metrics library
- Monitoring AWS Resources
- Monitoring HAProxy
- Monitoring Kubernetes
- Monitoring NGINX
- Monitoring NGINX Ingress Controller
- Monitoring NGINX Ingress Controller with VTS metrics
- Alert Management
- Error Tracking
- Tracing
- Incident Management
- GitLab Status Page
- Feature Flags
- GitLab CI/CD
- GitLab CI/CD pipeline configuration reference
- GitLab CI/CD include examples
- Introduction to CI/CD with GitLab
- Getting started with GitLab CI/CD
- How to enable or disable GitLab CI/CD
- Using SSH keys with GitLab CI/CD
- Migrating from CircleCI
- Migrating from Jenkins
- Auto DevOps
- Getting started with Auto DevOps
- Requirements for Auto DevOps
- Customizing Auto DevOps
- Stages of Auto DevOps
- Upgrading PostgreSQL for Auto DevOps
- Cache dependencies in GitLab CI/CD
- GitLab ChatOps
- Cloud deployment
- Docker integration
- Building Docker images with GitLab CI/CD
- Using Docker images
- Building images with kaniko and GitLab CI/CD
- GitLab CI/CD environment variables
- Predefined environment variables reference
- Where variables can be used
- Deprecated GitLab CI/CD variables
- Environments and deployments
- Protected Environments
- GitLab CI/CD Examples
- Test a Clojure application with GitLab CI/CD
- Using Dpl as deployment tool
- Testing a Phoenix application with GitLab CI/CD
- End-to-end testing with GitLab CI/CD and WebdriverIO
- DevOps and Game Dev with GitLab CI/CD
- Deploy a Spring Boot application to Cloud Foundry with GitLab CI/CD
- How to deploy Maven projects to Artifactory with GitLab CI/CD
- Testing PHP projects
- Running Composer and NPM scripts with deployment via SCP in GitLab CI/CD
- Test and deploy Laravel applications with GitLab CI/CD and Envoy
- Test and deploy a Python application with GitLab CI/CD
- Test and deploy a Ruby application with GitLab CI/CD
- Test and deploy a Scala application to Heroku
- GitLab CI/CD for external repositories
- Using GitLab CI/CD with a Bitbucket Cloud repository
- Using GitLab CI/CD with a GitHub repository
- GitLab Pages
- GitLab Pages
- GitLab Pages domain names, URLs, and baseurls
- Create a GitLab Pages website from scratch
- Custom domains and SSL/TLS Certificates
- GitLab Pages integration with Let's Encrypt
- GitLab Pages Access Control
- Exploring GitLab Pages
- Incremental Rollouts with GitLab CI/CD
- Interactive Web Terminals
- Optimizing GitLab for large repositories
- Metrics Reports
- CI/CD pipelines
- Pipeline Architecture
- Directed Acyclic Graph
- Multi-project pipelines
- Parent-child pipelines
- Pipelines for Merge Requests
- Pipelines for Merged Results
- Merge Trains
- Job artifacts
- Pipeline schedules
- Pipeline settings
- Triggering pipelines through the API
- Review Apps
- Configuring GitLab Runners
- GitLab CI services examples
- Using MySQL
- Using PostgreSQL
- Using Redis
- Troubleshooting CI/CD
- GitLab Package Registry
- GitLab Container Registry
- Dependency Proxy
- GitLab Composer Repository
- GitLab Conan Repository
- GitLab Maven Repository
- GitLab NPM Registry
- GitLab NuGet Repository
- GitLab PyPi Repository
- API Docs
- API resources
- .gitignore API
- GitLab CI YMLs API
- Group and project access requests API
- Appearance API
- Applications API
- Audit Events API
- Avatar API
- Award Emoji API
- Project badges API
- Group badges API
- Branches API
- Broadcast Messages API
- Project clusters API
- Group clusters API
- Instance clusters API
- Commits API
- Container Registry API
- Custom Attributes API
- Dashboard annotations API
- Dependencies API
- Deploy Keys API
- Deployments API
- Discussions API
- Dockerfiles API
- Environments API
- Epics API
- Events
- Feature Flags API
- Feature flag user lists API
- Freeze Periods API
- Geo Nodes API
- Group Activity Analytics API
- Groups API
- Import API
- Issue Boards API
- Group Issue Boards API
- Issues API
- Epic Issues API
- Issues Statistics API
- Jobs API
- Keys API
- Labels API
- Group Labels API
- License
- Licenses API
- Issue links API
- Epic Links API
- Managed Licenses API
- Markdown API
- Group and project members API
- Merge request approvals API
- Merge requests API
- Project milestones API
- Group milestones API
- Namespaces API
- Notes API
- Notification settings API
- Packages API
- Pages domains API
- Pipeline schedules API
- Pipeline triggers API
- Pipelines API
- Project Aliases API
- Project import/export API
- Project repository storage moves API
- Project statistics API
- Project templates API
- Projects API
- Protected branches API
- Protected tags API
- Releases API
- Release links API
- Repositories API
- Repository files API
- Repository submodules API
- Resource label events API
- Resource milestone events API
- Resource weight events API
- Runners API
- SCIM API
- Search API
- Services API
- Application settings API
- Sidekiq Metrics API
- Snippets API
- Project snippets
- Application statistics API
- Suggest Changes API
- System hooks API
- Tags API
- Todos API
- Users API
- Project-level Variables API
- Group-level Variables API
- Version API
- Vulnerabilities API
- Vulnerability Findings API
- Wikis API
- GraphQL API
- Getting started with GitLab GraphQL API
- GraphQL API Resources
- API V3 to API V4
- Validate the .gitlab-ci.yml (API)
- User Docs
- Abuse reports
- User account
- Active sessions
- Deleting a User account
- Permissions
- Personal access tokens
- Profile preferences
- Threads
- GitLab and SSH keys
- GitLab integrations
- Git
- GitLab.com settings
- Infrastructure as code with Terraform and GitLab
- GitLab keyboard shortcuts
- GitLab Markdown
- AsciiDoc
- GitLab Notification Emails
- GitLab Quick Actions
- Autocomplete characters
- Reserved project and group names
- Search through GitLab
- Advanced Global Search
- Advanced Syntax Search
- Time Tracking
- GitLab To-Do List
- Administrator Docs
- Reference architectures
- Reference architecture: up to 1,000 users
- Reference architecture: up to 2,000 users
- Reference architecture: up to 3,000 users
- Reference architecture: up to 5,000 users
- Reference architecture: up to 10,000 users
- Reference architecture: up to 25,000 users
- Reference architecture: up to 50,000 users
- Troubleshooting a reference architecture set up
- Working with the bundled Consul service
- Configuring PostgreSQL for scaling
- Configuring GitLab application (Rails)
- Load Balancer for multi-node GitLab
- Configuring a Monitoring node for Scaling and High Availability
- NFS
- Working with the bundled PgBouncer service
- Configuring Redis for scaling
- Configuring Sidekiq
- Admin Area settings
- Continuous Integration and Deployment Admin settings
- Custom instance-level project templates
- Diff limits administration
- Enable and disable GitLab features deployed behind feature flags
- Geo nodes Admin Area
- GitLab Pages administration
- Health Check
- Job logs
- Labels administration
- Log system
- PlantUML & GitLab
- Repository checks
- Repository storage paths
- Repository storage types
- Account and limit settings
- Service templates
- System hooks
- Changing your time zone
- Uploads administration
- Abuse reports
- Activating and deactivating users
- Audit Events
- Blocking and unblocking users
- Broadcast Messages
- Elasticsearch integration
- Gitaly
- Gitaly Cluster
- Gitaly reference
- Monitoring GitLab
- Monitoring GitLab with Prometheus
- Performance Bar
- Usage statistics
- Object Storage
- Performing Operations in GitLab
- Cleaning up stale Redis sessions
- Fast lookup of authorized SSH keys in the database
- Filesystem Performance Benchmarking
- Moving repositories managed by GitLab
- Run multiple Sidekiq processes
- Sidekiq MemoryKiller
- Switching to Puma
- Understanding Unicorn and unicorn-worker-killer
- User lookup via OpenSSH's AuthorizedPrincipalsCommand
- GitLab Package Registry administration
- GitLab Container Registry administration
- Replication (Geo)
- Geo database replication
- Geo with external PostgreSQL instances
- Geo configuration
- Using a Geo Server
- Updating the Geo nodes
- Geo with Object storage
- Docker Registry for a secondary node
- Geo for multiple nodes
- Geo security review (Q&A)
- Location-aware Git remote URL with AWS Route53
- Tuning Geo
- Removing secondary Geo nodes
- Geo data types support
- Geo Frequently Asked Questions
- Geo Troubleshooting
- Geo validation tests
- Disaster Recovery (Geo)
- Disaster recovery for planned failover
- Bring a demoted primary node back online
- Automatic background verification
- Rake tasks
- Back up and restore GitLab
- Clean up
- Namespaces
- Maintenance Rake tasks
- Geo Rake Tasks
- GitHub import
- Import bare repositories
- Integrity check Rake task
- LDAP Rake tasks
- Listing repository directories
- Praefect Rake tasks
- Project import/export administration
- Repository storage Rake tasks
- Generate sample Prometheus data
- Uploads migrate Rake tasks
- Uploads sanitize Rake tasks
- User management
- Webhooks administration
- X.509 signatures
- Server hooks
- Static objects external storage
- Updating GitLab
- GitLab release and maintenance policy
- Security
- Password Storage
- Custom password length limits
- Restrict allowed SSH key technologies and minimum length
- Rate limits
- Webhooks and insecure internal web services
- Information exclusivity
- How to reset your root password
- How to unlock a locked user from the command line
- User File Uploads
- How we manage the TLS protocol CRIME vulnerability
- User email confirmation at sign-up
- Security of running jobs
- Proxying assets
- CI/CD Environment Variables
- Contributor and Development Docs
- Contribute to GitLab
- Community members & roles
- Implement design & UI elements
- Issues workflow
- Merge requests workflow
- Code Review Guidelines
- Style guides
- GitLab Architecture Overview
- CI/CD development documentation
- Database guides
- Database Review Guidelines
- Database Review Guidelines
- Migration Style Guide
- What requires downtime?
- Understanding EXPLAIN plans
- Rake tasks for developers
- Mass inserting Rails models
- GitLab Documentation guidelines
- Documentation Style Guide
- Documentation structure and template
- Documentation process
- Documentation site architecture
- Global navigation
- GitLab Docs monthly release process
- Telemetry Guide
- Usage Ping Guide
- Snowplow Guide
- Experiment Guide
- Feature flags in development of GitLab
- Feature flags process
- Developing with feature flags
- Feature flag controls
- Document features deployed behind feature flags
- Frontend Development Guidelines
- Accessibility & Readability
- Ajax
- Architecture
- Axios
- Design Patterns
- Frontend Development Process
- DropLab
- Emojis
- Filter
- Frontend FAQ
- GraphQL
- Icons and SVG Illustrations
- InputSetter
- Performance
- Principles
- Security
- Tooling
- Vuex
- Vue
- Geo (development)
- Geo self-service framework (alpha)
- Gitaly developers guide
- GitLab development style guides
- API style guide
- Go standards and style guidelines
- GraphQL API style guide
- Guidelines for shell commands in the GitLab codebase
- HTML style guide
- JavaScript style guide
- Migration Style Guide
- Newlines style guide
- Python Development Guidelines
- SCSS style guide
- Shell scripting standards and style guidelines
- Sidekiq debugging
- Sidekiq Style Guide
- SQL Query Guidelines
- Vue.js style guide
- Instrumenting Ruby code
- Testing standards and style guidelines
- Flaky tests
- Frontend testing standards and style guidelines
- GitLab tests in the Continuous Integration (CI) context
- Review Apps
- Smoke Tests
- Testing best practices
- Testing levels
- Testing Rails migrations at GitLab
- Testing Rake tasks
- End-to-end Testing
- Beginner's guide to writing end-to-end tests
- End-to-end testing Best Practices
- Dynamic Element Validation
- Flows in GitLab QA
- Page objects in GitLab QA
- Resource class in GitLab QA
- Style guide for writing end-to-end tests
- Testing with feature flags
- Translate GitLab to your language
- Internationalization for GitLab
- Translating GitLab
- Proofread Translations
- Merging translations from CrowdIn
- Value Stream Analytics development guide
- GitLab subscription
- Activate GitLab EE with a license