My need is to be able to create from command line issues in Gitlab project (the context is to populate Gitlab Issues in MoReFEM project - the issues previously on a Redmine were unfortunately lost but I wanted to remain consistent with its indexing).
There is a documentation for this, but I had to tinker a bit to understand how to make it work; the notes below are to avoid losing that time again next time I need it.
- The command to read existing issues (from project indexed 17213):
curl --header "PRIVATE-TOKEN: <my_token>" https://gitlab.inria.fr/api/v4/projects/17213/issues | jq .
As you see, the project needs to be addressed by its integer id, not by its name. The jq
command is to provide a user-friendly output; jq
was installed through Homebrew on my macOS.
The access token is created easily on the settings for the project.
- To create new issues:
curl --request POST --header "PRIVATE-TOKEN: <my_token>" --header "Content-Type: application/json" --data @data.json https://gitlab.inria.fr/api/v4/projects/27317/issues | jq .
where data.json
is file with the informations for the issue.
- An issue can't be closed on creation, so we need the following command:
curl --request PUT --header "PRIVATE-TOKEN: <my_token>" --header "Content-Type: application/json" --data '{ "state_event" : "close" }' https://gitlab.inria.fr/api/v4/projects/27317/issues/10 | jq .
where 10 is the issue id to be closed.
Beware: PUT, not POST!