How to use the GitLab REST API

The GitLab API allows you to perform many of the actions you typically do when using the user interface. Using the API allows us to automate the process and eliminate any user interaction.

Valentin Despa
DevOps with Valentine

--

The GitLab API comes in two flavors: the REST API and the GraphQL API. For people just getting started with APIs, the REST API is much easier to understand and use. So this is what I will be demoing in this tutorial.

How to use the GitLab REST API

The GitLab API specification defines various endpoints based on the action we want to perform.

Let’s do a simple request using Postman.

I am using gitlab.com, so the GitLab API base URL will be this:

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

If you are self-hosting GitLab, your base URL will look like this:

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

I will call the projects endpoint to get a list of all public projects.

A status 200 OK will indicate that the request has been successful.

If you want to get details about a project, all you need is to append the project id to the URL.

--

--

Valentin Despa
DevOps with Valentine

Software developer, educator & overlander • GitLab Hero • AWS Community Builder • Postman Supernova • Imprint: http://vdespa.com/imprint