Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the GitLab API?

Tags:

gitlab

After reading the documentation on GitLab's API I could only find the following example URL:

https://gitlab.example.com/api/v4/

But I'm wondering what the root URL of the API of my projects on GitLab is? I've tried https://gitlab.com/api/v4/ with the Private-Token header set to a Personal Access Token I've created for myself, but it always returns 401: Unauthorized.

What is the correct URL and method to connect to GitLab's API?

like image 461
Robin De Schepper Avatar asked Oct 14 '25 18:10

Robin De Schepper


2 Answers

The https://gitlab.example.com/api/v4/ is API address of your GitLab instance (if you are using GitLab.com, choose https://gitlab.com/api/v4/ instead) , and /api/v4/ is a prefix and should be used for all scenarios!
GitLab API provides so many resources, see: GitLab API

Some examples:

You need to get your project's releases (Projects API):

curl --header "PRIVATE-TOKEN`:` ${YOUR_TOKEN}" http://gitlab.example.com/api/v4/projects/${PROJECT_ID}/releases/

You want to create a new Issue (Issue API):

curl --header 'Content-Type:application/json' --header "PRIVATE-TOKEN`:` ${YOUR_TOKEN}" --request POST "http://gitlab.example.com/api/v4/projects/${PROJECT_ID}/issues?title=${ISSUE_TITLE}&labels=${LABELS}&description=${ISSUE_DESCRIPTION}"
like image 143
MrRolling Avatar answered Oct 17 '25 20:10

MrRolling


Be careful about access tokens. You have to create a personal access token, not a deploy token.

How to create access token

like image 30
Sayf-Eddine Avatar answered Oct 17 '25 20:10

Sayf-Eddine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!