PHPackages                             emri99/gitlab-generic-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. emri99/gitlab-generic-api-client

ActiveLibrary[API Development](/categories/api)

emri99/gitlab-generic-api-client
================================

PHP GitLab generic API client (not stick to any version)

v3.0.0(5y ago)19.3k↓33.3%MITPHPPHP &gt;=5.4CI failing

Since May 27Pushed 5y ago1 watchersCompare

[ Source](https://github.com/emri99/gitlab-generic-api-client)[ Packagist](https://packagist.org/packages/emri99/gitlab-generic-api-client)[ Docs](https://github.com/emri99/gitlab-generic-api-client)[ RSS](/packages/emri99-gitlab-generic-api-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Gitlab-api-generic-client
=========================

[](#gitlab-api-generic-client)

[![Build Status](https://camo.githubusercontent.com/5bacea70245baab6d163d7840c1ab769926bda6e01890d0bd7822f9de19e8070/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f656d726939392f6769746c61622d67656e657269632d6170692d636c69656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/emri99/gitlab-generic-api-client)[![PHP: 5.4](https://camo.githubusercontent.com/a9864d5f4ff7096b10a6ee6e2c5f49aec393f854aebde12d3157c6ee548f4eef/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d352e342d626c75652e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![License: MIT](https://camo.githubusercontent.com/1b01ef0024ba0866c115986b895301f657c1b21fc29f05c4844b7f2e8d89204d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)

This library has been built keeping in mind that Gitlab move so fast, that it becomes hard to apply changes and migration guides on complex code base.

How it works
------------

[](#how-it-works)

This code is inpired by npm package [gitlab-api-client](https://www.npmjs.com/package/gitlab-api-client).
Next lines descriptions too.

Main principle: All paths are build generically.
You aren't stick to any specific API version as you will have access to all the gitlab API endpoints, even for those that haven't been defined yet.

Installation
------------

[](#installation)

```
composer require emri99/gitlab-generic-api-client

```

Usage
-----

[](#usage)

### Authentication

[](#authentication)

- Authenticate using HTTP token

```
$client->authenticate('SECRET-HTTP-TOKEN', GitlabApiClient::AUTH_HTTP_TOKEN);
```

- Authenticate using OAUTH token

```
$client->authenticate('SECRET-OAUTH-TOKEN', GitlabApiClient::AUTH_OAUTH_TOKEN);
```

### Requesting

[](#requesting)

- GET request

```
$client = new GitlabApiClient('https://my.gitlab.com/api/v4');
$branches = $client->projects(1)
    ->repository()
    ->branches()
    ->get()

// will send GET request on
// https://my.gitlab.com/api/v4/projects/1/repository/branches.

foreach($branches as $branch) {
    echo $branch->name, "\n";
}
```

- POST request

```
# create a variable secret
$variableDatas = $this->getClient()
    ->projects(2)
    ->variables()
    ->post([
        'key' => 'SECRET',
        'value' => 'password'
    ]);
```

- PUT request

```
# protect a branch
$branchUpdated = $this->getClient()
    ->projects(2)
    ->repository()
    ->branches('master')
    ->protect()->put([
        'developers_can_push' => false,
        'developers_can_merge' => false
    ]);
$done = $branchUpdated->protected;
```

- DELETE request

```
# delete a branch
$branchUpdated = $this->getClient()
    ->projects(2)
    ->repository()
    ->branches('obsolet-feature')
    ->delete();
```

### Special case

[](#special-case)

If an url segment is the same than a public method of `GitlabApiClient`, this remains possible to build to path correctly.

For example, to build path `user/1/delete`, use:

```
$client->user(1, 'delete');

```

### IDE Completion depending on gitlab api version (optional)

[](#ide-completion-depending-on-gitlab-api-version-optional)

Empty classes can be used to simulate code completion on retrieved object by installing `emri99/gitlab-generic-api-client-models`. This [optional package](https://github.com/emri99/gitlab-generic-api-client-models) is tagged by gitlab API version.

*Currently there isn't many versions handled, only the one I'm using. ie: 9.1.4*

> When using this package, retrieved objects **WONT BE** instance of models class.
> Retrieved objects remains `stdclass`. This is **ONLY** used for IDE completion.

```
composer require emri99/gitlab-generic-api-client-models:YOUR_GITLAB_VERSION --dev

```

YOU **MUST** add phpdoc to use completion like below:

- **GET**

```
$client = new GitlabApiClient('https://my.gitlab.com/api/v4');

/**
 * $branches aint really a Branch instance
 * @var Branch[] $branches
 */
$branches = $client->projects(1)
    ->repository()
    ->branches()
    ->get(array(
        // parameters
    ))

// $branches is an array of stdclass having
// the same properties than a Branch class
foreach($branches as $branch) {
    echo $branch->name;
}
```

Contributing
============

[](#contributing)

Thanks for contributing !

Please follow this rules:

- you MUST apply supplied CS-fixer by running `composer run-script cs`
- you MUST write/update the tests
- you SHOULD write documentation
- you MUST write minimum details in pull request description

Squashing many commits to avoid noise on git logs make sense too ;)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~252 days

Recently: every ~314 days

Total

6

Last Release

2014d ago

Major Versions

1.0.0 → 2.0.02017-06-03

v2.0.3 → v3.0.02020-11-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5d47125257c182ff8a5e72301cda22bb478d2be62a063890d662c9476286c04?d=identicon)[emri99](/maintainers/emri99)

---

Top Contributors

[![emri99](https://avatars.githubusercontent.com/u/6652177?v=4)](https://github.com/emri99 "emri99 (23 commits)")

---

Tags

gitlabgitlab-apiphpapigitlab

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/emri99-gitlab-generic-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/emri99-gitlab-generic-api-client/health.svg)](https://phpackages.com/packages/emri99-gitlab-generic-api-client)
```

###  Alternatives

[m4tthumphrey/php-gitlab-api

GitLab API v4 client for PHP

9485.4M64](/packages/m4tthumphrey-php-gitlab-api)[zeichen32/gitlabapibundle

Symfony Bundle to include the gitlab api.

57417.0k2](/packages/zeichen32-gitlabapibundle)[messagemedia/messages-sdk

The MessageMedia Messages API provides a number of endpoints for building powerful two-way messaging applications.

13390.6k](/packages/messagemedia-messages-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
