我已经在我的gitlab.com帐户上创建了项目和存储库,生成了私钥,现在我正在尝试执行api调用来获取提交列表。
现在,我想通过api从documentation https://docs.gitlab.com/ce/api/projects.html#list-projects获取项目列表。
GET /projects
所以我在做
curl --header "PRIVATE-TOKEN: XXXXXXX -c" "https://gitlab.com/projects"
得到404分。我尝试了几种组合,但找不到正确的基本url。
https://docs.gitlab.com/ce/api/commits.html表示,存储库提交、文档记录也是如此
https://gitlab.example.com/api/v3/projects/5/repository/commits
很好,我正在尝试(以myusername/projectname作为项目id) https://gitlab.com/api/v3/projects/myusername/projectname/repository/commits
也得到了404分
发布于 2016-09-29 07:16:28
托管GitLab的正确基本url是https://gitlab.com/api/v4/
,因此您对
curl --header "PRIVATE-TOKEN: XXXXXX" "https://gitlab.com/api/v4/projects"
这将返回您可见的所有项目,包括其他用户的公共项目。
如果您只想查看您的项目,那么应该使用GET /users/:user_id/projects
端点,其中:user_id
是您的用户ID,可以在您的GitLab profile page中找到,如果您通过身份验证,则可以在对GET /user
的请求的响应中找到该ID。
# Get :user_id from this request
curl --header "PRIVATE-TOKEN: XXXXXX" "https://gitlab.com/api/v4/user"
# See your projects by replacing :user_id with id value from previous request
curl --header "PRIVATE-TOKEN: XXXXXX" "https://gitlab.com/api/v4/users/:user_id/projects"
此外,项目ID与项目名称不同。您可以从对GET /users/:user_id/projects
的请求响应中检索项目ID,也可以从项目的设置页面中检索。
发布于 2019-01-27 06:12:22
对我来说,以下请求起作用了:
curl --header "PRIVATE-TOKEN: YOUR_TOKEN" "https://gitlab.com/api/v4/users/YOUR_USER_ID/projects"
不知道为什么会有这样的请求:curl --header "PRIVATE-TOKEN: PRIVATE_TOKEN" "https://gitlab.com/api/v4/projects/"
返回了一个包含其他公共项目的列表。
另一个有用的用户信息请求:curl --header "PRIVATE-TOKEN: PRIVATE_TOKEN" "https://gitlab.com/api/v4/user/"
发布于 2018-08-03 01:01:57
https://docs.gitlab.com/ee/api/#basic-usage
尝试此命令: curl "https://gitlab.example.com/api/v4/projects“,如文档中所示
如果您使用的是Gitlab的version3,则使用curl --header "Authorization: Bearer -TOKEN“https://gitlab.example.com/api/v3/projects
还有"python-gitlab“模块,可以帮助你轻松地从项目名称中获取Id - https://python-gitlab.readthedocs.io/en/stable/
https://stackoverflow.com/questions/39751840
复制相似问题