GitLab API
The GitLab API provides a powerful way to interact with GitLab programmatically through its REST API. It allows you to automate tasks, integrate with other applications, and build custom tools that extend GitLab’s functionality.
Authentication
The GitLab API requires authentication to access resources. You can authenticate using:
- Personal access tokens: Create a personal access token with the required scopes on your GitLab profile. https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
- OAuth 2.0: Use OAuth 2.0 to authenticate your application. https://docs.gitlab.com/ee/api/oauth2.html
API Endpoints
The GitLab API is organized around a set of resources, such as Projects, Users, Groups, and Repositories. Each resource has its own set of endpoints, allowing you to perform actions like:
- Creating: Create new resources, such as projects or issues.
- Reading: Retrieve information about existing resources.
- Updating: Modify existing resources.
- Deleting: Remove resources.
Examples
Here are some examples of how to use the GitLab API:
- Create a new project:
curl --request POST \
--url 'https://gitlab.com/api/v4/projects' \
--header 'PRIVATE-TOKEN: <your_access_token>' \
--header 'Content-Type: application/json' \
--data '{"name": "My New Project", "namespace_id": 1234}'
- Get information about a project:
curl --request GET \
--url 'https://gitlab.com/api/v4/projects/1234' \
--header 'PRIVATE-TOKEN: <your_access_token>'
- Create a new issue:
curl --request POST \
--url 'https://gitlab.com/api/v4/projects/1234/issues' \
--header 'PRIVATE-TOKEN: <your_access_token>' \
--header 'Content-Type: application/json' \
--data '{"title": "My New Issue", "description": "This is a new issue"}'
Resources
- API documentation: https://docs.gitlab.com/ee/api/index.html
- API Explorer: -/tree/master/ee/app/assets/javascripts/api/explorer
Code Examples
For code examples in various languages, you can refer to the following resources:
- Ruby: -/ee/lib/gitlab/api/v4/client.rb
- Python: -/ee/spec/requests/api/v4/projects_spec.rb
- JavaScript: -/ee/spec/requests/api/v4/projects_spec.rb
This outlines the GitLab API and provides resources to help you get started. Remember to always refer to the official API documentation for the most up-to-date information and to understand the available options and their limitations.