找不到基本的GitLab API基本URL

abo*_*sun 20 api gitlab

我已经在我的gitlab.com帐户上创建了项目和回购,生成了私钥,现在我正在尝试api调用以获取提交列表.

现在我想通过api获取项目列表,来自文档 https://docs.gitlab.com/ce/api/projects.html#list-projects

GET /projects
Run Code Online (Sandbox Code Playgroud)

所以我在做

curl --header "PRIVATE-TOKEN: XXXXXXX -c" "https://gitlab.com/projects"
Run Code Online (Sandbox Code Playgroud)

得到404.我已经尝试了几种组合,但找不到正确的基本网址.

对于存储库提交也是如此,文档https://docs.gitlab.com/ce/api/commits.html

https://gitlab.example.com/api/v3/projects/5/repository/commits
Run Code Online (Sandbox Code Playgroud)

好的,我正在尝试(使用myusername/projectname作为项目ID) https://gitlab.com/api/v3/projects/myusername/projectname/repository/commits

并得到了404

Bro*_*ary 23

对于托管GitLab正确的基本网址为https://gitlab.com/api/v4/使您的要求
GET /projects

curl --header "PRIVATE-TOKEN: XXXXXX" "https://gitlab.com/api/v4/projects"
Run Code Online (Sandbox Code Playgroud)

此外,项目ID与项目名称不同.您可以从请求的响应中检索项目IDGET /users/:user_id/projects

  • 我用我的访问令牌尝试过这个,但它让我得到了其他人的项目 (3认同)
  • 是否有任何片段可以自动将人类看到的 gitlab url 转换为 api url? (2认同)

dej*_*dej 8

对我来说,以下请求有效:

curl --header "PRIVATE-TOKEN: YOUR_TOKEN" "https://gitlab.com/api/v4/users/YOUR_USER_ID/projects" 
Run Code Online (Sandbox Code Playgroud)

不知道为什么请求:curl --header "PRIVATE-TOKEN: PRIVATE_TOKEN" "https://gitlab.com/api/v4/projects/"返回了一个包含其他一些公共项目的列表。

另一个有用的用户信息请求: curl --header "PRIVATE-TOKEN: PRIVATE_TOKEN" "https://gitlab.com/api/v4/user/"