gitlabtagsgitlab-api

Why do I do wrong with gitlab API?


I'm a bit of a loss here is my problem:

I have to input the version of a project in the footer of an angular application, so I was trying to get access to the tags of the project since they are supposed to contain only the version of the project at each push (AGILE project management method etc etc),

So I've tried to follow the gitlab's documentation: https://docs.gitlab.com/ee/api/rest/ https://docs.gitlab.com/ee/api/tags.html

Now here is my input and output in windows cmd:

curl --header "PRIVATE-TOKEN: <read-api-token>" \ --url "https://gitlab.com/api/v5/projects/<id-of-the-project>/repository/tags"
curl: (3) URL rejected: Bad hostname
<html><body>You are being <a href="https://gitlab.com/users/sign_in">redirected</a>.</body></html>

The URL of my project is: https://gitlab.com/poleprojets/hnde/hnde-front

I've got my id from here: A picture of how I took my id, actions button on the top left of the project page

A picture of the summary of the token I did provide to my curl request: enter image description here

So if anyone can help me figuring out where I did fail my request I would be glad or a post that could be pertinent regarding this issue.

Since I'm here asking, if anyone here got an idea of how else I could get the version I would be glad if you could share it.

Well I was expecting a list of tags objects

I also tried to test things through postman by putting the get request and setting up the header, not much results here

EDIT: After looking carrefully I found out the example uses v4 not v5, yet it doesn't fix the problem

curl --header "PRIVATE-TOKEN: <read-api-token>" \   --url "https://gitlab.com/api/v4/projects/<id>/repository/tags"
curl: (3) URL rejected: Bad hostname
{"message":"403 Forbidden"}

Solution

  • The right API version is v4. You're being redirected because of a non-existing API version. Now you get 403 Forbidden, which means something is wrong with user or token permissions. The read_api token should satisfy you (I checked with my Gitlab instance, and it works). Potentially it can be issue with the User's scope: try to set (at lest to play around) the maintainer role and try to make HTTP request again.

    Again, the command below works on my GitLab:

    curl --header 'PRIVATE-TOKEN: glpat-xxxxxxxxxx' --url https://gitlab.com/api/v4/projects/150/repository/tags