Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access GitLab issues using CURL?

Tags:

curl

gitlab

I'd like to get a list of the issues for the project YYYYYY and a username XXXXXX.

curl --header "PRIVATE-TOKEN: myownprivatetoken" "https://gitlab.com/api/v3/projects/YYYYYY/issues"

curl --header "PRIVATE-TOKEN: myownprivatetoken" --header "SUDO: XXXXXX" "https://gitlab.com/api/v3/projects/YYYYYY/issues"

curl --header "PRIVATE-TOKEN: myownprivatetoken" "https://gitlab.com/api/v3/XXXXXX/projects/YYYYYY/issues"

But they only return:

{"message":"404 Project Not Found"}

or

<html><body>You are being <a href="https://gitlab.com/users/sign_in">redirected</a>.</body></html>

It seems to me that I have misinterpreted the API docs at http://doc.gitlab.com/ce/api/issues.html and http://doc.gitlab.com/ce/api/README.html .

So what am I doing wrong?

like image 634
Edward Avatar asked Aug 04 '15 09:08

Edward


2 Answers

The documentation tell you this about how to retrieve issues from a project:

GET /projects/:id/issues

And you tried:

curl --header "PRIVATE-TOKEN: xxx" "https://gitlab.com/api/v3/projects/YYYYYY/issues"

This is correct, but the parameter you give YYYYYY has to be the project id, so it has to be an integer, not text with the project name or path. You need to use something like :

curl --header "PRIVATE-TOKEN: xxx" "https://gitlab.com/api/v3/projects/234/issues"

Where 234 is the id of your project. To get this integer id of your project, simply do a :

curl --header "PRIVATE-TOKEN: xxx" "https://gitlab.com/api/v3/projects

This will list all your projects and will give you the unique integer identifier of a project in the id field:

[
  {
    "id": 4,            <-------- //This one
    "name": "my super mega project",
    "description": null,
    .....
like image 174
PierreF Avatar answered Nov 14 '22 10:11

PierreF


Since GitLab v11.x the /api/v3 returns error "API V3 is no longer supported. Use API V4 instead."

As of version v11 and v12, this works:

curl --header 'PRIVATE-TOKEN: mySecret' https://gitlab.com/api/v4/projects
/2/merge_requests

Parse the output (I recommend jq for that):

[
  {
    "id": 2,            <-------------- use this number below
    "name": "Duke Nukem 3D",

And then:

curl --header 'PRIVATE-TOKEN: mySecret' https://gitlab.com/api/v4/projects/2/issues
like image 26
kubanczyk Avatar answered Nov 14 '22 12:11

kubanczyk