4

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?

2 Answers 2

7

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}"
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I don't know what is different from what I've tried but today it decided to work, thanks.
1

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

How to create access token

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.