API


Overview

GitLab offers a very extensive API

The API is located at /api/v4/

The notes how to use the API include:

Resources

Resources for every aspect of GitLab


Authentication

Authentication using a token (personal/group/project)

Send token in HTTP header using Private-Token:

curl "https://gitlab.example.com/api/v4/projects" \
    --header "Private-Token: <your_access_token>"

Pagination

Pagination done by offset

GitLab API returns HTTP headers:

Header Description
x-next-page Index of next page
x-page Index of current page
x-per-page Number of items per page
x-prev-page Index of previous page
x-total Total number of items
x-total-pages Total number of pages

Keyset-based pagination is also supported


Hands-On

  1. Retrieve projects using a private access token:

     curl http://gitlab.${DOMAIN}/api/v4/projects \
         --silent \
         --header "Private-Token: <TOKEN>"
    
  2. Check pagination headers:

     curl http://gitlab.${DOMAIN}/api/v4/projects \
         --silent \
         --verbose \
         --header "Private-Token: <TOKEN>"
    

glab helps talking with the API