Skip to content

Gitlab API calls using POSTMAN

AnkshitJain edited this page Jan 24, 2018 · 1 revision

This page lists the responses given by Gitlab API.
These responses recorded are for Gitlab CE version 10.1.4.
Note: The session section for obtaining private token was removed from 10.2.0 version of Gitlab CE.
It's last documentation can be found here.
The Gitlab hostname used everywhere is localhost.
The admin details used are:

Admin User Name: root
Admin Password: 12345678
  1. Purpose: Get a private token from Gitlab.
    Note: This can be done by any user and his given credentials. Here, the user is root.
    URL: https://localhost/api/v4/session
    Type: POST
    Request Body:

      login: root
      password: 12345678
    

    Response:

    Status: 201 Created
    {
        "id": 1,
        "name": "Administrator",
        "username": "root",
        "state": "active",
        "avatar_url": "https://secure.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
        "web_url": "https://localhost/root",
        "created_at": "2018-01-23T16:04:33.734Z",
        "bio": null,
        "location": null,
        "skype": "",
        "linkedin": "",
        "twitter": "",
        "website_url": "",
        "organization": null,
        "last_sign_in_at": null,
        "confirmed_at": "2018-01-23T16:04:33.656Z",
        "last_activity_on": null,
        "email": "admin@example.com",
        "theme_id": 1,
        "color_scheme_id": 1,
        "projects_limit": 100000,
        "current_sign_in_at": null,
        "identities": [],
        "can_create_group": true,
        "can_create_project": true,
        "two_factor_enabled": false,
        "external": false,
        "is_admin": true,
        "private_token": "smSNt6qLDY-fXksrLCAU"
    }
    
  2. Purpose: Get details of the all the users on Gitlab.
    Note: This can only be done with a private token obtained by an admin user.
    URL: https://localhost/api/v4/users?private_token=smSNt6qLDY-fXksrLCAU
    Type: GET
    Request Body: -
    Response Body:

    Status: 200 OK
    [
     {   
         "id": 1,
         "name": "Administrator",
         "username": "root",
         "state": "active",
         "avatar_url": "https://secure.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
         "web_url": "https://localhost/root",
         "created_at": "2018-01-23T16:04:33.734Z",
         "bio": null,
         "location": null,
         "skype": "",
         "linkedin": "",
         "twitter": "",
         "website_url": "",
         "organization": null,
         "last_sign_in_at": null,
         "confirmed_at": "2018-01-23T16:04:33.656Z",
         "last_activity_on": null,
         "email": "admin@example.com",
         "theme_id": 1,
         "color_scheme_id": 1,
         "projects_limit": 100000,
         "current_sign_in_at": null,
         "identities": [],
         "can_create_group": true,
         "can_create_project": true,
         "two_factor_enabled": false,
         "external": false,
         "is_admin": true
     },
     {
         "id": 79,
         "name": "User1",
         "username": "User1",
         "state": "active",
         "avatar_url": "https://secure.gravatar.com/avatar/59029276955677351421b3ff6bf5ee4c?s=80&d=identicon",
         "web_url": "https://localhost/User1",
         "created_at": "2018-01-23T22:36:53.896Z",
         "bio": null,
         "location": null,
         "skype": "",
         "linkedin": "",
         "twitter": "",
         "website_url": "",
         "organization": null,
         "last_sign_in_at": "2018-01-23T22:36:53.924Z",
         "confirmed_at": "2018-01-23T22:36:53.889Z",
         "last_activity_on": null,
         "email": "user1@gmail.com",
         "theme_id": 1,
         "color_scheme_id": 1,
         "projects_limit": 100000,
         "current_sign_in_at": "2018-01-23T22:36:53.924Z",
         "identities": [],
         "can_create_group": true,
         "can_create_project": true,
         "two_factor_enabled": false,
         "external": false,
         "is_admin": false
     }
    ]
    
  3. Purpose: Create a user on Gitlab.
    Note: user123 is the user to be created. This can only be done with a private token obtained by an admin user.
    URL: https://localhost/api/v4/users?private_token=smSNt6qLDY-fXksrLCAU
    Type: POST
    Request Body:

      name: user123
      username: user123
      password: 12345678
      email: user123@example.com
      skip_confirmation: true
    

    Response Body:

    Status: 201 Created
    {
        "id": 80,
        "name": "user123",
        "username": "user123",
        "state": "active",
        "avatar_url": "https://secure.gravatar.com/avatar/6a69ec475f1c9f5aa2c37fb382f9ae7b?s=80&d=identicon",
        "web_url": "https://localhost/user123",
        "created_at": "2018-01-23T22:45:07.353Z",
        "bio": null,
        "location": null,
        "skype": "",
        "linkedin": "",
        "twitter": "",
        "website_url": "",
        "organization": null,
        "last_sign_in_at": null,
        "confirmed_at": "2018-01-23T22:45:07.346Z",
        "last_activity_on": null,
        "email": "user123@example.com",
        "theme_id": 1,
        "color_scheme_id": 1,
        "projects_limit": 100000,
        "current_sign_in_at": null,
        "identities": [],
        "can_create_group": true,
        "can_create_project": true,
        "two_factor_enabled": false,
        "external": false
    }
    

    Trying the same request the second time for the same user: Response Body:

    Status: 409 Conflict
    {
      "message": "Email has already been taken"
    }
    
  4. Purpose: Delete a user from Gitlab.
    Note: 80 is the id of the user that is to be deleted. This can only be done with a private token obtained by an admin user.
    URL: https://localhost/api/v4/users/80?private_token=smSNt6qLDY-fXksrLCAU
    Type: DELETE
    Request Body:

      id: 80
      hard_delete: true
    

    Response Body:

    Status: 204 No Content
    

    Trying the same request the second time for the same user:
    Response Body:

    Status: 404 Not Found
    {
        "message": "404 User Not Found"
    }
    
  5. Purpose: Create a project on Gitlab for a specific user.
    Note: project1 is created for user1. The private token used here in the URL is obtained from the access credentials of user1.
    URL: https://localhost/api/v4/projects?private_token=u9QShmy9zpFs9FTXoRrr
    Type: POST
    Request Body:

      name: project1
    

    Response Body:

    Status: 201 Created
    {
        "id": 47,
        "description": null,
        "default_branch": null,
        "tag_list": [],
        "ssh_url_to_repo": "git@localhost:user1/project1.git",
        "http_url_to_repo": "https://localhost/user1/project1.git",
        "web_url": "https://localhost/user1/project1",
        "name": "project1",
        "name_with_namespace": "user1 / project1",
        "path": "project1",
        "path_with_namespace": "user1/project1",
        "avatar_url": null,
        "star_count": 0,
        "forks_count": 0,
        "created_at": "2018-01-24T10:38:31.122Z",
        "last_activity_at": "2018-01-24T10:38:31.122Z",
        "_links": {
            "self": "http://localhost/api/v4/projects/47",
            "issues": "http://localhost/api/v4/projects/47/issues",
            "merge_requests": "http://localhost/api/v4/projects/47/merge_requests",
            "repo_branches": "http://localhost/api/v4/projects/47/repository/branches",
            "labels": "http://localhost/api/v4/projects/47/labels",
            "events": "http://localhost/api/v4/projects/47/events",
            "members": "http://localhost/api/v4/projects/47/members"
        },
        "archived": false,
        "visibility": "private",
        "owner": {
            "id": 83,
            "name": "user1",
            "username": "user1",
            "state": "active",
            "avatar_url": "https://secure.gravatar.com/avatar/111d68d06e2d317b5a59c2c6c5bad808?s=80&d=identicon",
            "web_url": "https://localhost/user1"
        },
        "resolve_outdated_diff_discussions": false,
        "container_registry_enabled": true,
        "issues_enabled": true,
        "merge_requests_enabled": true,
        "wiki_enabled": true,
        "jobs_enabled": true,
        "snippets_enabled": true,
        "shared_runners_enabled": true,
        "lfs_enabled": true,
        "creator_id": 83,
        "namespace": {
            "id": 82,
            "name": "user1",
            "path": "user1",
            "kind": "user",
            "full_path": "user1",
            "parent_id": null
        },
        "import_status": "none",
        "import_error": null,
        "open_issues_count": 0,
        "runners_token": "emrES-M3tuFxUUsZQkYC",
        "public_jobs": true,
        "ci_config_path": null,
        "shared_with_groups": [],
        "only_allow_merge_if_pipeline_succeeds": false,
        "request_access_enabled": false,
        "only_allow_merge_if_all_discussions_are_resolved": false,
        "printing_merge_request_link_enabled": true
    }
    

    Trying the same request the second time for the same user:
    Response Body:

    Status: 400 Bad Request
    {
        "message": {
            "route.path": [
                "has already been taken"
            ],
            "route": [
                "is invalid"
            ],
            "path": [
                "has already been taken"
            ],
            "name": [
                "has already been taken"
            ],
            "limit_reached": []
        }
    }
    
Clone this wiki locally
You can’t perform that action at this time.