GitLab API Documentation

website·Indexed 36 days ago

https://j3tpwu47lj.apifox.cn

OpenAPI 3.0.1 specifications for GitLab API v4 endpoints, including project management, user retrieval, group access, branch operations, commit history, and Webhook creation.

Tokens
7.3K
Snippets
31
Records
50
Agent score
50%

What's inside GitLab

  1. Retrieve a single user from GitLab API

    Retrieve detailed information about a specific user by providing their User ID in the path. This request requires a GitLab personal token passed in the request header for authentication.
    curl --request GET \
      --url http://<your-gitlab-instance>/api/v4/users/686 \
      --header 'PRIVATE-TOKEN: glpat-q1csJCWcYYGum_xZxHhg'
  2. Retrieve a specific branch from a GitLab project

    Use the GitLab API to get detailed information about a specific branch within a project. This includes the branch name, commit details (ID, author, date, message), protection status, and permissions (whether developers can push or merge).
    curl --request GET \
      --url 'https://{gitlab-domain}/api/v4/projects/{project_id}/repository/branches/{branch_name}' \
      --header 'PRIVATE-TOKEN: <your_personal_token>'
  3. Retrieve GitLab project details and ID

    Use the GitLab API to retrieve detailed information about projects, including the unique project ID, repository URLs, and access levels. The API returns a project object containing critical identifiers such as id, path_with_namespace, and web_url, as well as configuration settings for CI/CD, merge requests, and visibility.
    // Example Project Response
    {
      "id": 1773,
      "description": "",
      "name": "Ais Fuel Predict",
      "name_with_namespace": "郭有根 / Ais Fuel Predict",
      "path": "ais_fuel_predict",
      "path_with_namespace": "guoyougen/ais_fuel_predict",
      "web_url": "https://git.csntcorp.com/guoyougen/ais_fuel_predict",
      "ssh_url_to_repo": "git@git.csntcorp.com:guoyougen/ais_fuel_predict.git",
      "http_url_to_repo": "https://git.csntcorp.com/guoyougen/ais_fuel_predict.git",
      "visibility": "internal",
      "archived": false,
      "permissions": {
        "project_access": {
          "access_level": 30,
          "notification_level": 0
        },
        "group_access": null
      }
    }
  4. Parameters for retrieving a GitLab project branch

    To retrieve a specific branch, the following parameters are required:

    Path Parameters:

    • 项目ID (Project ID): The unique ID of the project (e.g., 111).
    • 分支名称 (Branch Name): The name of the branch to retrieve (e.g., dev).

    Header Parameters:

    • PRIVATE-TOKEN: Your GitLab personal access token used for authentication.
  5. Understand the GitLab project branches response schema

    The API returns an array of branch objects. Each object contains:

    • name: The name of the branch.
    • commit: An object containing commit details including id, short_id, title, message, author_name, and web_url.
    • merged: Boolean indicating if the branch has been merged.
    • protected: Boolean indicating if the branch is protected.
    • default: Boolean indicating if this is the default branch.
    • web_url: The URL to the branch on the GitLab web interface.
    • can_push, developers_can_push, developers_can_merge: Permissions flags for pushing and merging.
  6. User object schema for GitLab API

    The API returns a JSON object representing the user. Key fields include:

    • id (integer): Unique user ID
    • username (string): User's handle
    • name (string): Full name
    • state (string): Account state (e.g., active)
    • avatar_url (string): URL to the user's avatar
    • web_url (string): URL to the user's profile page
    • created_at (string): Timestamp of account creation
    • bot (boolean): Indicates if the user is a bot account
    • followers/following (integer): Social counts
  7. Understand the Project object schema for Get Project List API

    The /api/v4/projects endpoint returns a list of project objects. Each project object contains comprehensive metadata including repository URLs, visibility settings, access levels, and CI/CD configurations. Key fields include ssh_url_to_repo, http_url_to_repo, and web_url for repository access, as well as a namespace object containing the group or user ownership details.
    {
      "id": 1832,
      "description": "企业微信订餐后端",
      "name": "food",
      "name_with_namespace": "胥龙飞 / food",
      "path": "food",
      "path_with_namespace": "xulongfei/food",
      "created_at": "2024-10-14T16:32:42.490+08:00",
      "default_branch": "main",
      "tag_list": [],
      "topics": [],
      "ssh_url_to_repo": "string",
      "http_url_to_repo": "string",
      "web_url": "string",
      "namespace": {
        "id": 123,
        "name": "string",
        "path": "string",
        "kind": "string",
        "full_path": "string",
        "parent_id": null,
        "avatar_url": "string",
        "web_url": "string"
      }
    }
  8. GitLab Project List API Response Schema

    The /api/v4/projects endpoint returns an array of project objects. Key fields include:

    • Identification: id (integer), name (string), path (string), path_with_namespace (string).
    • URLs: web_url (browser link), ssh_url_to_repo (SSH clone URL), http_url_to_repo (HTTP clone URL).
    • Metadata: created_at (timestamp), default_branch (string), visibility (string), archived (boolean).
    • Stats: forks_count (integer), star_count (integer), open_issues_count (integer).
    • Nested Objects:
      • namespace: Contains details about the project's group or user owner (id, name, full_path, kind).
      • owner: Details about the project owner (id, username, name).
      • _links: HATEOAS links to related resources like issues, merge_requests, and repo_branches.
    • Feature Flags: Booleans indicating if issues_enabled, merge_requests_enabled, wiki_enabled, jobs_enabled, and container_registry_enabled are active.
  9. Understand the Project object schema

    The project list response contains objects with the following key fields:

    • id: Unique identifier for the project.
    • name: The name of the project.
    • name_with_namespace: The project name including its namespace (e.g., 'user / project').
    • path_with_namespace: The URL path including the namespace.
    • ssh_url_to_repo: The SSH clone URL.
    • http_url_to_repo: The HTTP clone URL.
    • web_url: The URL to view the project in a browser.
    • visibility: The visibility level (e.g., internal).
    • owner: Object containing the owner's id, username, and name.
    • _links: A map of API endpoints for related resources such as issues, repo_branches, labels, events, and members.
    • Feature Flags: Boolean indicators for enabled features like issues_enabled, merge_requests_enabled, wiki_enabled, and container_registry_enabled.
  10. Retrieve a list of projects via API

    Use the GET /api/v4/projects endpoint to retrieve a list of projects. The response returns an array of project objects containing detailed metadata including repository URLs, namespace information, visibility settings, and CI/CD configurations.
    GET /api/v4/projects
  11. Configure parameters for the Get Single User API

    The 'Get Single User' endpoint requires the following parameters:

    • Path Parameter: 用户ID (User ID) - The unique identifier of the user (e.g., 686). Required.
    • Header Parameter: PRIVATE-TOKEN - A valid GitLab personal access token used for authentication.
  12. Configure parameters for the Get All Users API

    The GET /api/v4/users endpoint accepts the following parameters:

    • Header: PRIVATE-TOKEN (String) - Required. Your GitLab personal access token.
    • Query: page (String) - Optional. Used for pagination (e.g., page=6).