2017 © Pedro Peláez
 

library redmine-api

Redmine API client

image

kbsali/redmine-api

Redmine API client

  • Monday, November 13, 2017
  • by kbsali
  • Repository
  • 41 Watchers
  • 340 Stars
  • 177,625 Installations
  • PHP
  • 20 Dependents
  • 0 Suggesters
  • 153 Forks
  • 16 Open issues
  • 55 Versions
  • 8 % Grown

The README.md

PHP Redmine API

Latest Version Software License Build Status Codecov Total Downloads, (*1)

A simple PHP Object Oriented wrapper for Redmine API., (*2)

Uses Redmine API., (*3)

Features

  • Follows PSR-4 conventions and coding standard: autoload friendly
  • Choose between using native cURL function or any PSR-18 HTTP client implementation like Guzzle for handling http connections
  • mid-level API e.g., (*4)

    $client->getApi('issue')->create(['project_id' => 1, 'subject' => 'issue title']);
    
    $response = $client->getApi('issue')->getLastResponse();
    
  • low-level API e.g. php $response = $client->request( HttpFactory::makeJsonRequest( 'POST', '/issues.json', '{"issue":{"project_id":1,"subject":"issue title"}}', ), );

Supported Redmine versions

We support (and run tests against) the latest supported Redmine versions that receive security updates., (*5)

  • Redmine 5.1.x
  • Redmine 5.0.x
  • Redmine 4.2.x

Nevertheless, you can also use this library for all older Redmine versions. In this case, however, be aware that some features might not be supported by your Redmine server., (*6)

If a new Redmine version enables new features that are not yet supported with this library, you are welcome to create an issue., (*7)

Requirements

  • PHP ^7.4 || ^8.0
  • The PHP SimpleXML extension
  • The PHP JSON extension
  • Enabled REST web service on your Redmine server
    • Go to Administration -> Settings -> Api (/settings/edit?tab=api) and check the "Enable REST web service" box
    • Obtain your API access key in your profile page: /my/account
    • (or use your username & password; not recommended)

Optional

  • The PHP cURL extension if you want to use the native cURL functions.
  • PHPUnit >= 9.0 (optional) to run the test suite

Todo

  • Tracking of Redmine API feature support in #305
  • Check header's response code (especially for POST/PUT/DELETE requests)
    • See https://stackoverflow.com/questions/9183178/php-curl-retrieving-response-headers-and-body-in-a-single-request/9183272#9183272

Limitations / Missing Redmine-API

Redmine is missing some APIs for a full remote management of the data:, (*8)

Install

By using Composer you can simply run:, (*9)

$ php composer.phar require kbsali/redmine-api

at the root of your projects. To utilize the library, include Composer's vendor/autoload.php in the scripts that will use the Redmine classes., (*10)

For example,, (*11)

<?php
// This file is generated by Composer
require_once 'vendor/autoload.php';

$client = new \Redmine\Client\NativeCurlClient('https://redmine.example.com', '0ef19567656532f8dd43a4dbfeda787f01f3e659');

For a manual installation please follow this instruction., (*12)

Running the test suite

You can run test suite to make sure the library will work properly on your system. Simply run vendor/bin/phpunit in the project's directory :, (*13)

$ vendor/bin/phpunit
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

Warning:       No code coverage driver available

...............................................................  63 / 432 ( 14%)
............................................................... 126 / 432 ( 29%)
............................................................... 189 / 432 ( 43%)
............................................................... 252 / 432 ( 58%)
............................................................... 315 / 432 ( 72%)
............................................................... 378 / 432 ( 87%)
......................................................          432 / 432 (100%)

Time: 00:00.149, Memory: 14.00 MB

OK (432 tests, 1098 assertions)

Basic usage of php-redmine-api client

Start your project

Create your project e.g. in the index.php by require the vendor/autoload.php file., (*14)

+<?php
+
+require_once 'vendor/autoload.php';

Instantiate a Redmine Client

You can choose between:, (*15)

  1. a native curl client or
  2. the PSR-18 compatible client.

1. Native curl Client Redmine\Client\NativeCurlClient

:bulb: This client was introduced in php-redmine-api v1.8.0. If you are using the old Redmine\Client please see this migration guide for help to upgrade your code., (*16)

You will need a URL to your Redmine instance and either a valid Apikey..., (*17)

<?php

require_once 'vendor/autoload.php';
+
+// Instantiate with ApiKey
+$client = new \Redmine\Client\NativeCurlClient('https://redmine.example.com', '1234567890abcdfgh');

... or valid username/password., (*18)

<?php

require_once 'vendor/autoload.php';
+
+// Instantiate with Username/Password (not recommended)
+$client = new \Redmine\Client\NativeCurlClient('https://redmine.example.com', 'username', 'password');

:bulb: For security reason it is recommended that you use an ApiKey rather than your username/password., (*19)

cURL configuration

After you instantiate a client you can set some optional cURL settings., (*20)

<?php

require_once 'vendor/autoload.php';

// Instantiate with ApiKey
$client = new Redmine\Client\NativeCurlClient('https://redmine.example.com', '1234567890abcdfgh');
+
+// [OPTIONAL] if you want to check the servers' SSL certificate on Curl call
+$client->setCurlOption(CURLOPT_SSL_VERIFYPEER, true);
+
+// [OPTIONAL] set the port (it will try to guess it from the url)
+$client->setCurlOption(CURLOPT_PORT, 8080);
+
+// [OPTIONAL] set a custom host
+$client->setCurlOption(CURLOPT_HTTPHEADER, ['Host: https://custom.example.com']);

2. Psr-18 compatible Client Redmine\Client\Psr18Client

:bulb: This client was introduced in v1.7.0 of this library. If you are using the old Redmine\Client please follow this migration guide., (*21)

The Psr18Client requires, (*22)

  • a Psr\Http\Client\ClientInterface implementation (like guzzlehttp/guzzle), see
  • a Psr\Http\Message\RequestFactoryInterface implementation (like guzzlehttp/psr7), see
  • a Psr\Http\Message\StreamFactoryInterface implementation (like guzzlehttp/psr7), see
  • a URL to your Redmine instance
  • an Apikey or username
  • and optional a password if you want tu use username/password.

:bulb: For security reason it is recommended that you use an ApiKey rather than your username/password., (*23)

<?php

require_once 'vendor/autoload.php';
+
+$guzzle = new \GuzzleHttp\Client();
+$psr17Factory = new \GuzzleHttp\Psr7\HttpFactory();
+
+// Instantiate with ApiKey
+$client = new \Redmine\Client\Psr18Client(
+    $guzzle,
+    $psr17Factory,
+    $psr17Factory,
+    'https://redmine.example.com',
+    '1234567890abcdfgh'
+);
+// ...or Instantiate with Username/Password (not recommended)
+$client = new \Redmine\Client\Psr18Client(
+    $guzzle,
+    $psr17Factory,
+    $psr17Factory,
+    'https://redmine.example.com',
+    'username',
+    'password'
+);
Guzzle configuration

Because the Psr18Client is agnostic about the HTTP client implementation every configuration specific to the transport has to be set to the Psr\Http\Client\ClientInterface implementation., (*24)

This means that if you want to set any cURL settings to Guzzle you have multiple ways to set them:, (*25)

  1. Using Guzzle environment variables
  2. Using request options inside a Psr\Http\Client\ClientInterface wrapper:
<?php

require_once 'vendor/autoload.php';

+use Psr\Http\Client\ClientInterface;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+
$guzzle = \GuzzleHttp\Client();
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();

+$guzzleWrapper = new class(\GuzzleHttp\Client $guzzle) implements ClientInterface
+{
+    private $guzzle;
+
+    public function __construct(\GuzzleHttp\Client $guzzle)
+    {
+        $this->guzzle = $guzzle;
+    }
+
+    public function sendRequest(RequestInterface $request): ResponseInterface
+    {
+        return $this->guzzle->send($request, [
+            // Set the options for every request here
+            'auth' => ['username', 'password', 'digest'],
+            'cert' => ['/path/server.pem', 'password'],
+            'connect_timeout' => 3.14,
+            // Set specific CURL options, see https://docs.guzzlephp.org/en/stable/faq.html#how-can-i-add-custom-curl-options
+            'curl' => [
+                CURLOPT_SSL_VERIFYPEER => 1,
+                CURLOPT_SSL_VERIFYHOST => 2,
+                CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2,
+            ],
+        ]);
+    }
+};
+
// Instantiate with ApiKey
$client = new \Redmine\Client\Psr18Client(
-    $guzzle,
+    $guzzleWrapper,
    $psr17Factory,
    $psr17Factory,
    'https://redmine.example.com',
    '1234567890abcdfgh'
);

Built-in Redmine features

Impersonate User

Redmine allows you to impersonate another user. This can be done using the methods startImpersonateUser() and stopImpersonateUser()., (*26)

$client->startImpersonateUser('kim');
// all requests will now impersonate the user `kim`

// To stop impersonation
$client->stopImpersonateUser();

API usage

You can now use the getApi() method to create and get a specific Redmine API., (*27)

<?php

$client->getApi('user')->list();
$client->getApi('user')->listLogins();

$client->getApi('issue')->create([
    'project_id'  => 'test',
    'subject'     => 'some subject',
    'description' => 'a long description blablabla',
    'assigned_to_id' => 123, // or 'assigned_to' => 'user1' OR 'groupXX'
]);
$client->getApi('issue')->list([
    'limit' => 1000
]);

See further examples and read more about usage in the docs., (*28)

Thanks!

The Versions

13/11 2017

dev-master

9999999-dev https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • ext-curl *
  • php ^5.4 || ^7.0
  • ext-simplexml *
  • ext-json *

 

The Development Requires

api redmine

13/11 2017

v1.5.16

1.5.16.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0
  • ext-curl *
  • ext-simplexml *
  • ext-json *

 

The Development Requires

api redmine

29/05 2017

v1.5.15

1.5.15.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php ^5.4 || ^7.0
  • ext-curl *

 

The Development Requires

api redmine

19/04 2017

v1.5.14

1.5.14.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

06/02 2017

v1.5.13

1.5.13.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

22/11 2016

v1.5.12

1.5.12.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

05/10 2016

v1.5.11

1.5.11.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

20/09 2016

v1.5.10

1.5.10.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

20/09 2016

dev-misc

dev-misc https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

01/07 2016

v1.5.9

1.5.9.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

30/06 2016

v1.5.8

1.5.8.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

07/01 2016

v1.5.7

1.5.7.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

21/11 2015

v1.5.6

1.5.6.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

24/08 2015

v1.5.5

1.5.5.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

11/05 2015

v1.5.4

1.5.4.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

05/03 2015

v1.5.3

1.5.3.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

05/03 2015

dev-params

dev-params https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

26/12 2014

v1.5.2

1.5.2.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

05/11 2014

v1.5.1

1.5.1.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

02/10 2014

1.2.x-dev

1.2.9999999.9999999-dev https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

02/10 2014

v1.2.1

1.2.1.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

30/08 2014

v1.5.0

1.5.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

14/07 2014

v1.4

1.4.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

10/06 2014

v1.3

1.3.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.4
  • ext-curl *

 

The Development Requires

api redmine

13/05 2014

v1.2

1.2.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

08/05 2014

v1.1.3

1.1.3.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

26/03 2014

v1.1.2

1.1.2.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

28/02 2014

v1.1.1

1.1.1.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

28/02 2014

v1.1.0

1.1.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

13/12 2013

v1.0.10

1.0.10.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

13/12 2013

1.0.9

1.0.9.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

13/12 2013

1.0.8

1.0.8.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

29/11 2013

1.0.7

1.0.7.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

12/11 2013

1.0.6

1.0.6.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

12/11 2013

1.0.5

1.0.5.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

12/11 2013

1.0.4

1.0.4.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

14/10 2013

1.0.2

1.0.2.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

01/10 2013

1.0.0

1.0.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

16/07 2013

0.4.11

0.4.11.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

14/07 2013

0.4.10

0.4.10.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

19/06 2013

0.4.9

0.4.9.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

31/05 2013

0.4.8

0.4.8.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

02/05 2013

0.4.7

0.4.7.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

14/03 2013

0.4.6

0.4.6.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

06/03 2013

0.4.5

0.4.5.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

08/01 2013

0.4.4

0.4.4.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

07/01 2013

0.4.3

0.4.3.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

06/01 2013

0.4.2

0.4.2.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

19/11 2012

0.4.1

0.4.1.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

13/11 2012

0.4.0

0.4.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

22/10 2012

0.3.0

0.3.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

22/10 2012

0.2.2

0.2.2.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

17/10 2012

0.2.1

0.2.1.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

08/10 2012

0.1

0.1.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine

08/10 2012

0.2

0.2.0.0 https://github.com/kbsali/php-redmine-api

Redmine API client

  Sources   Download

MIT

The Requires

  • php >=5.3.2
  • ext-curl *

 

api redmine