| ... | ... | @@ -39,7 +39,7 @@ API 请求应以`api`和 API 版本为前缀,API 版本在[`lib/api.rb`](https |
|
|
|
使用 cURL 的有效 API 请求的示例:
|
|
|
|
|
|
|
|
```
|
|
|
|
curl "https://codechina.csdn.net/api/v4/projects"
|
|
|
|
curl "https://gitcode.net/api/v4/projects"
|
|
|
|
```
|
|
|
|
|
|
|
|
该 API 使用 JSON 序列化数据,您无需在 API URL 的末尾指定`.json` 。
|
| ... | ... | @@ -65,13 +65,13 @@ curl "https://codechina.csdn.net/api/v4/projects" |
|
|
|
在参数中使用个人访问令牌的示例:
|
|
|
|
|
|
|
|
```
|
|
|
|
curl "https://codechina.csdn.net/api/v4/projects?private_token=<your_access_token>"
|
|
|
|
curl "https://gitcode.net/api/v4/projects?private_token=<your_access_token>"
|
|
|
|
```
|
|
|
|
|
|
|
|
在头文件使用个人访问令牌的示例:
|
|
|
|
|
|
|
|
```
|
|
|
|
curl --header "Private-Token: <your_access_token>" "https://codechina.csdn.net/api/v4/projects"
|
|
|
|
curl --header "Private-Token: <your_access_token>" "https://gitcode.net/api/v4/projects"
|
|
|
|
```
|
|
|
|
|
|
|
|
## 状态码[](#status-codes "Permalink")
|
| ... | ... | @@ -126,7 +126,7 @@ API 可以根据上下文和操作返回不同的状态码,如果请求导致 |
|
|
|
在下面的示例中,我们每页列出 50 个名称空间。
|
|
|
|
|
|
|
|
```
|
|
|
|
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://codechina.csdn.net/api/v4/namespaces?per_page=50"
|
|
|
|
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitcode.net/api/v4/namespaces?per_page=50"
|
|
|
|
```
|
|
|
|
|
|
|
|
#### 分页链接头[](#pagination-link-header "Permalink")
|
| ... | ... | @@ -136,7 +136,7 @@ curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://codech |
|
|
|
在下面的 cURL 调用例子中,我们限制输出到每页 3 项( `per_page=3` ),我们要求的第二页( `page=2`的) 评论与 ID 问题的`8`属于与 ID 项目`8` :
|
|
|
|
|
|
|
|
```
|
|
|
|
curl --head --header "PRIVATE-TOKEN: <your_access_token>" "https://codechina.csdn.net/api/v4/projects/8/issues/8/notes?per_page=3&page=2"
|
|
|
|
curl --head --header "PRIVATE-TOKEN: <your_access_token>" "https://gitcode.net/api/v4/projects/8/issues/8/notes?per_page=3&page=2"
|
|
|
|
```
|
|
|
|
|
|
|
|
响应将是:
|
| ... | ... | @@ -147,7 +147,7 @@ Cache-Control: no-cache |
|
|
|
Content-Length: 1103
|
|
|
|
Content-Type: application/json
|
|
|
|
Date: Mon, 18 Jan 2020 09:43:18 GMT
|
|
|
|
Link: <https://codechina.csdn.net/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"
|
|
|
|
Link: <https://gitcode.net/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
|
| ... | ... | @@ -189,7 +189,7 @@ X-Total-Pages: 3 |
|
|
|
在下面的示例中,我们每页列出 50 [个项目](/docs/user/project-) ,并按`id`升序排列。
|
|
|
|
|
|
|
|
```
|
|
|
|
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://codechina.csdn.net/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc"
|
|
|
|
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitcode.net/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc"
|
|
|
|
```
|
|
|
|
|
|
|
|
响应头包括指向下一页的链接,例如:
|
| ... | ... | @@ -197,8 +197,8 @@ curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://codech |
|
|
|
```
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
...
|
|
|
|
Links: <https://codechina.csdn.net/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
|
|
|
|
Link: <https://codechina.csdn.net/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
|
|
|
|
Links: <https://gitcode.net/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
|
|
|
|
Link: <https://gitcode.net/api/v4/projects?pagination=keyset&per_page=50&order_by=id&sort=asc&id_after=42>; rel="next"
|
|
|
|
Status: 200 OK
|
|
|
|
...
|
|
|
|
```
|
| ... | ... | @@ -232,7 +232,7 @@ DELETE /projects/:id/share/:group_id |
|
|
|
因此,对 ID 为`5` ,组 ID 为`17`的项目的 cURL 调用为:
|
|
|
|
|
|
|
|
```
|
|
|
|
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://codechina.csdn.net/api/v4/projects/5/share/17"
|
|
|
|
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitcode.net/api/v4/projects/5/share/17"
|
|
|
|
```
|
|
|
|
|
|
|
|
**注意:**必须遵循要求进行 URL 编码的路径参数。 如果不是,它将与 API 接口不匹配并以 404 进行响应。如果 API 前面有某些内容(例如 Apache),请确保它不会对 URL 编码的路径参数进行解码。
|
| ... | ... | @@ -291,7 +291,7 @@ URL 编码的查询字符串具有长度限制,请求太大将导致`414 Reque |
|
|
|
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
|
|
|
|
-d "import_sources[]=github" \
|
|
|
|
-d "import_sources[]=bitbucket" \
|
|
|
|
https://codechina.csdn.net/api/v4/some_endpoint
|
|
|
|
https://gitcode.net/api/v4/some_endpoint
|
|
|
|
```
|
|
|
|
|
|
|
|
### `hash`[](#hash "Permalink")
|
| ... | ... | @@ -305,7 +305,7 @@ curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ |
|
|
|
--form "file=@/path/to/somefile.txt"
|
|
|
|
--form "override_params[visibility]=private" \
|
|
|
|
--form "override_params[some_other_param]=some_value" \
|
|
|
|
https://codechina.csdn.net/api/v4/projects/import
|
|
|
|
https://gitcode.net/api/v4/projects/import
|
|
|
|
```
|
|
|
|
|
|
|
|
### hash 键对[](#array-of-hashes "Permalink")
|
| ... | ... | @@ -314,12 +314,12 @@ https://codechina.csdn.net/api/v4/projects/import |
|
|
|
|
|
|
|
```
|
|
|
|
curl --globoff --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
|
|
|
|
"https://codechina.csdn.net/api/v4/projects/169/pipeline?ref=master&variables[][key]=VAR1&variables[][value]=hello&variables[][key]=VAR2&variables[][value]=world"
|
|
|
|
"https://gitcode.net/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://codechina.csdn.net/api/v4/projects/169/pipeline"
|
|
|
|
"https://gitcode.net/api/v4/projects/169/pipeline"
|
|
|
|
```
|
|
|
|
|
|
|
|
## `id` vs `iid`[](#id-vs-iid "Permalink")
|
| ... | ... | |