Coder Social home page Coder Social logo

kbsali / php-redmine-api Goto Github PK

View Code? Open in Web Editor NEW
420.0 38.0 185.0 1.48 MB

A simple PHP Redmine API client, Object Oriented

License: MIT License

PHP 90.05% Gherkin 9.95%
php redmine looking-for-maintainer maintainer-wanted api-client composer-package

php-redmine-api's Introduction

PHP Redmine API

Latest Version Software License Build Status Codecov Total Downloads

A simple PHP Object Oriented wrapper for Redmine API.

Uses Redmine API.

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.
    $client->getApi('issue')->create(['project_id' => 1, 'subject' => 'issue title']);
  • low-level API e.g.
    $client->requestPost('/issues.json', '{"issue":{"project_id":1,"subject":"issue title"}}');

Supported Redmine versions

We support (and run tests against) the latest Redmine versions that are actively maintained.

  • Redmine 5.1.x
  • Redmine 5.0.x

Nevertheless, you can also use this library for all older Redmine versions. In this case, however, be aware that some features may not yet be supported by your Redmine server.

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

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

Limitations / Missing Redmine-API

Redmine is missing some APIs for a full remote management of the data:

Install

By using Composer you can simply run:

$ 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.

For example,

<?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.

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 :

$ 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.

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

Instantiate a Redmine Client

You can choose between:

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

1. Native curl Client Redmine\Client\NativeCurlClient

💡 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.

You will need a URL to your Redmine instance and either a valid Apikey...

<?php

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

... or valid username/password.

<?php

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

💡 For security reason it is recommended that you use an ApiKey rather than your username/password.

cURL configuration

After you instantiate a client you can set some optional cURL settings.

<?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

💡 This client was introduced in v1.7.0 of this library. If you are using the old Redmine\Client please follow this migration guide.

The Psr18Client requires

  • 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.

💡 For security reason it is recommended that you use an ApiKey rather than your username/password.

<?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.

This means that if you want to set any cURL settings to Guzzle you have multiple ways to set them:

  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().

$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.

<?php

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

$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.

Thanks!

php-redmine-api's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-redmine-api's Issues

Custom fields problem

In your example to create an issue, you have

...
'custom_fields' => array(
'id' => 22,
'value' => 'some object'),
...

But I have multiple custom fields, and I needed to do

...
'custom_fields' => array(
array(
'id' => 22,
'value' => 'some object'),)
...

to get the custom field to be accepted.

API does not handle more than 25 projects in Redmine

The problem seems to be the function Api\Projects.all(), which simply calls the JSON API which doesn't return more than 25 projects if no limit is given. With limit, it returns up to 100 projects. To really make this usable, someone should either add a limit of 100 there, or should do a series of calls until all projects have been read in.

Allow attaching of uploaded file when creating an issue.

Hoi,

the upload api is already implemented into this lib and seems to work. But i do not see a way to attach the uploaded file to a new issue.

According to the Redmine API docs, it should be something like this:

$upload = json_decode( $client->api('attachment')->upload($filecontent) );

$client->api('issue')->create(
    array(
        'project_id' => 1,
        'assigned_to_id' => 1,
        'status_id' => 1,
        'subject' => 'Subject',
        'description' => 'Content',
        'uploads' => array(
            'upload' => array(
                'token' => $upload->upload->token,
                'filename' => 'file.pdf',
                'description' => 'File',
                'content_type' => 'application/pdf'
            )
        )
    )
);

But this results in the following warning:

Warning: SimpleXMLElement::addChild() expects parameter 2 to be string, array given in /.../website/vendor/kbsali/redmine-api/lib/Redmine/Api/Issue.php line 75 

Redmine API via SSL

On the install I'm working on we just switched over to SSL for security reasons but unfortunately it appears this library assumes HTTP so all my logic against the redmine api no longer works. I'd assume it would be mostly changes to the client.php usage of CURL.

https://gist.github.com/159552ef7d45a1553aa5

diff --git a/lib/Redmine/Client.php b/lib/Redmine/Client.php
index 6fad9b9..4082d7c 100644
--- a/lib/Redmine/Client.php
+++ b/lib/Redmine/Client.php
@@ -172,10 +172,11 @@ class Client
             curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
         }
         curl_setopt($curl, CURLOPT_URL, $this->url.$path);
-        curl_setopt($curl, CURLOPT_PORT , 80);
+        curl_setopt($curl, CURLOPT_PORT , 443);
         curl_setopt($curl, CURLOPT_VERBOSE, 0);
         curl_setopt($curl, CURLOPT_HEADER, 0);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

         $tmp = parse_url($path);
         if ('xml' === substr($tmp['path'], -3)) {

was enough to satisfy my immediate need.

Better solution as I see it is below:

  1. Check beginning of URL for http/ https
  2. Check URL for : portnum
  3. Add an additional function how how curl should treat SSL ignore invalid cert etc.

In this case it's selfsigned so it can't be verified.

Updates through API to write a comment fails with status 200 response

I'm trying to write a comment in redmine using the following line:

$issuenumber = 12345;
$comment = "api comment";
$client->api('issue')->update($issuenumber,['notes'=>$comment]);

But although the command doesn't fails and send a status 200 response, the response itself is empty, and the only thing changed in the redmine task is time at which it was last updated.

It appears to be a similar issue as documented here: http://www.redmine.org/issues/12496

Add support for travis-ci.com

It would suggest to let travis-ci.com run the tests for each commit:
https://travis-ci.org/

It accepted, I can commit a basic configuration file for it. All you have to do is set up the account on travis-ci.com as this is your repository. ;)

Custom fields for Issues when creating

We have use some custom fields it redmine tasks for some projects, and I was needs to add this functionality in php-redmine-api quickly.

Probably you find this functionality is allowed to add for php-redmine-api. Of course in more presentable format. :)

My solution is next:

  • in Redmine\Api\Issue class added this code in 'create' (and something like this in 'update') method:
...
       $params = $this->cleanParams($params);
        $params = array_filter(array_merge($defaults, $params));

        $xml = new \SimpleXMLElement('');
        foreach ($params as $k => $v) {

            // CUSTOMIZED: added custom fields
            if ($k == 'custom_fields' && is_array($v)) {
                $custom_fields_item = $xml->addChild('custom_fields', '');
                $custom_fields_item->addAttribute('type', 'array');

                foreach ($v as $field) {
                    $item = $custom_fields_item->addChild('custom_field', '');
                    $item->addAttribute('id', $field['id']);
                    $item->addChild('value', $field['value']);
                }

            } else {
                $item = $xml->addChild($k, $v);
            }
        }


        return $this->post('/issues.xml', $xml->asXML());
...

Create or update wiki page

Hi,

To create or update a wiki page, you have to use PUT method instead of POST.
I remove in my case the cleanParams function because it's not present in the Wiki class nor AbstractApi and I don't need it.

/**
     * Create a new issue given an array of $params
     * The issue is assigned to the authenticated user.
     * @link http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Creating-an-issue
     *
     * @param  int|string        $project the project name
     * @param  string            $page    the page name
     * @param  array             $params  the new issue data
     * @return \SimpleXMLElement
     */
    public function create($project, $page, array $params = array())
    {
        $defaults = array(
            'text'     => null,
            'comments' => null,
            'version'  => null,
        );
        //$params = $this->cleanParams($params);
        $params = array_filter(array_merge($defaults, $params));

        $xml = new \SimpleXMLElement('');
        foreach ($params as $k => $v) {
            $xml->addChild($k, $v);
        }

        return $this->put('/projects/'.$project.'/wiki/'.$page.'.xml', $xml->asXML());
    }

PS : In my case (again ;) ) I replace

$c = 'Api'.$classes[$name];
by
$c = 'Redmine\Api'.$classes[$name];
in Client.php

BR

Allow manual installation

Hello, I'd like to be able to install the library manually (i.e. without composer). Ultimately my goal is to package it for Gentoo, so that users can install it using our package manager, portage.

I've hit a problem though: unlike the other language install tools (rubygems, cabal, etc.), composer encourages you to use its autoload.php file instead of keeping track of includes at the top of each file. This sounds nice at first, until you try to install a library without composer -- if I use another package manager to install the library instead of composer, it doesn't work! All the include()s are missing.

Would it be possible to add the includes to the source files that need them? This should make it possible to install the library manually, and will also have the nice side effect of making the source easier to hack on without going through a composer install.

I've made the following changes locally and they were enough to get me started:

diff --git a/lib/Redmine/Api/AbstractApi.php b/lib/Redmine/Api/AbstractApi.php
index 0d64ed3..eaf61f2 100644
--- a/lib/Redmine/Api/AbstractApi.php
+++ b/lib/Redmine/Api/AbstractApi.php
@@ -2,6 +2,8 @@

 namespace Redmine\Api;

+require_once(dirname(__FILE__) . '/../Client.php');
+
 use Redmine\Client;

 /**
diff --git a/lib/Redmine/Api/Attachment.php b/lib/Redmine/Api/Attachment.php
index 5aad32b..e5068a9 100644
--- a/lib/Redmine/Api/Attachment.php
+++ b/lib/Redmine/Api/Attachment.php
@@ -2,6 +2,8 @@

 namespace Redmine\Api;

+require('AbstractApi.php');
+
 /**
  * Attachment details
  *
diff --git a/lib/Redmine/Client.php b/lib/Redmine/Client.php
index 48ae676..e025266 100644
--- a/lib/Redmine/Client.php
+++ b/lib/Redmine/Client.php
@@ -2,6 +2,27 @@

 namespace Redmine;

+require('Api/Attachment.php');
+require('Api/CustomField.php');
+require('Api/Group.php');
+require('Api/Issue.php');
+require('Api/IssueCategory.php');
+require('Api/IssuePriority.php');
+require('Api/IssueRelation.php');
+require('Api/IssueStatus.php');
+require('Api/Membership.php');
+require('Api/News.php');
+require('Api/Project.php');
+require('Api/Query.php');
+require('Api/Role.php');
+require('Api/SimpleXMLElement.php');
+require('Api/TimeEntry.php');
+require('Api/TimeEntryActivity.php');
+require('Api/Tracker.php');
+require('Api/User.php');
+require('Api/Version.php');
+require('Api/Wiki.php');
+
 use Redmine\Api\SimpleXMLElement;

 /**

Curl response was a one spaced string

Hi,
in file lib/Redmine/Client.php on line 389 there is curl response, and in my case, was an empty string " " and this thrown an exception on line 403 when it tries to instanciate SimpleXMLElement :

return new SimpleXMLElement($response);

I have checked $contentType which was 'application/xml'
In my case it occured when responseCode was 500 ( Project's tracker not defined )

To fix it i have add trim() on curl response, but may there is a better way to do it.

Best regards

pascall

Attachments missing for Wiki pages

As the wiki page and version endpoint can hold attachments, the Rest API supports ?include=attachments for the request.

As I recognized, issues already have a $params param for providing that or projects hardcodes ?include=trackers,issue_categories,attachments,relations.

Http Auth + apiKey

How can i use http basic authorization and apiKey
I find only one way to do this: pass as parameter each time.

$issueList = $redmine->api('issue')->all(array(
    'status_id' => 2,
    'limit' => 3,
    'key' => '208ddff4f4f4f7f4f7f8f737b369b8052d779c1',
  ));

but this is not good, to pass it every time.

Attachment on issue failed

$upload = json_decode( $client->api('attachment')->upload(file_get_contents('feedback.png')));

$issue = $client->api('issue')->create(array(
    'project_id'  => '3',
    'subject'     => 'Feedback',
    'description' => "desc"
));

$client->api('issue')->attach($issue->id, array(
    'token'        => $upload->upload->token,
    'description'  => 'Attachement',
    'content_type' => 'image/png'
));

$upload is null, and thus, issue have no attachment.

feedback.png is ok.
I've also tried with

$upload = json_decode( $client->api('attachment')->upload(base64_decode($img)))

(where $img is a base64 encode image, of course)
which IS an octet-stream, but it failed too.

Thks for any idea...

SimpleXMLElement::addChild(): unterminated entity reference

Writing a small import script for issues i experienced this error.

It happened when one of the issues had an & inside the description.
"http://www.exmple.org/blapage.aspx?PfId=415616&OtherId=231245&SomeOtherId=1&pref=plqv#.Ug5xIFJAeXE"

and it seems to be this problem:
http://stackoverflow.com/questions/17027043/unterminated-entity-reference-php

I could solve it by changing Issue.php line 90 from:
$xml->addChild($k, $v );
into
$xml->addChild($k);
$xml->$k = $v;

anyway that was just quickfix and we need to decide if this should be done on all XML creation methods or if the user needs to escape the data accordingly before inserting it into the redmine api (in that case it should be documented somewhere)

Ticket creation - Start_date problem

If i create a ticket, and i don´t want a start_date it isn´t possible. It replaced the empty "start_date" with the currently date from today.

example:

$client->api('issue')->create(array(
                            'project_id'  => $project_id,
                            'subject'     => $array_ticket['subject'],
                            'description' => $array_ticket['description'],
                            'assigned_to_id' => $array_ticket['assigned_to']['id'], 
                            'status_id' => $array_ticket['status']['id'],
                            'priority_id' => $array_ticket['priority']['id'],
                            'tracker_id' => $array_ticket['tracker']['id'],
                            'category_id' => $new_category_id,
                            'start_date' => null);

if i didn´t set the start_date it will also not work.

and something like none or 0 does not work, too.

Can you help me?

Features Missing from Library

I'm considering using this in a larger scope project where as groups,issue relationships,project memberships might be useful. Any reason these weren't currently supported?

Also when logging a time entries, I don't think using strings for activity worked. Using the activity ID I think it was ok. Any insight? I'd put code samples but I don't have it handy.

I'd be willing to collaborate on expanding the library to the rest of the Redmine API. Need to review the library code more before I'd be able to add additional handlers.

getIdByUsername didn´t work

Hello,

i wrote a script to create some users in our redmine system automatically. But many times we got an error because the function "getIdByUsername" gives a "False" back. I don´t know why this happend. The Username exist in our Redmine System. Everything seems okay.

$user_id = $client->api('user')->getIdByUsername($sheetData[$i]['J']);

some example for the structure of our usernames:

yes we use the e-mail adress also as the username/loginname

Can you help me with this problem? it seems that 70% of our tasks gone wrong because of this error!

How can i get server response and show a custom message while creating issue.

Hi,
I am a newbie to php and github. My goal is that when i create an issue, ı want to show a custom message to user if issue created or not.
Here is the code from example.php
<?php

require_once 'vendor/autoload.php';

// ----------------------------
// Instanciate a redmine client
// --> with ApiKey
$client = new Redmine\Client('http://localhost:8080/redmine/', 'abcd98789789');

// ----------------------------
// [OPTIONAL] set the port
// (it will try to guess it from the url)
$client->setPort(8080);

// ----------------------------
$client->api('issue')->create(array(
    'project_id'     => '13',
    'subject'        => 'test api (xml) 2',
    'description'    => 'test api',
    //'assigned_to_id' => '2',
    'tracker_id'         => '2',
));

Now what should i do to show an custom message to user.
I tried;
$val = $client->api('issue')->create(array(
'project_id' => '13',
'subject' => 'test api (xml) 2',
'description' => 'test api',
'tracker_id' => '3'
));

if($val) {
echo 'data sent';
}
else {
echo 'error';
}

var_dump($val);

i tried several other ways also but they did not work either.
Look forward to hear soon.

Read a Issue and get the Attachments

Hi,

i want to read a issue, and download all attachments from this single issue to create a second similar issue. But how can i look up which attachment a issue have? i only found the solution to get an attachment by it´s id.

On the official REST API from Readmine a found this line: Note: when getting an issue through the API, its attachments can also be retrieved in a single request using GET /issues/:id.:format?include=attachments.
See here: http://www.redmine.org/projects/redmine/wiki/Rest_Attachments

Can you help me with that?

Thanks a lot!

Search issues by description

Is this possible?
I have tried
$issues = $client->api('issue')->all(array('description' => 'abcd'));

Without success

Make limit optional

I think it would be better, if the limit is provided optional and default is set to no limit.
This would solve #46 too.

If you accept this issue, I can try to provide a PR with the needed changes. Just tell me if this should be implemented or not.

How set the option“inherited members” for projects

I create automatically with the rest api a lot of projects in Redmine.

But we have the problem that for every project we need to set manually the option "inherited members from parent projects" (i don´t know exactly the right spelling). This is very disappointing.

This is the snippet how we create a project:

$client->api('project')->create(array(
                'name'     => $project_name,
                'identifier' => $project_identifier,
                'tracker_ids' => $tracker_ids,
                'parent_id' => $produktions_projekt_id));

This work´s nicely. But i want to add something like this:

'inherited members' => true
'inherited members' => 1
'inherited members' => '1'

I tried these three options, but they didn´t worked. I hope someone of you can help me with this problem?

Thanks a lot!

I reported it also here: http://stackoverflow.com/questions/27148877/how-set-the-optioninherited-members-for-projects-with-the-rest-api-from-redmin

Can't seem to install php-redmine-api with composer

I added a composer.json to my project

{
    "require": {
        "kbsali/redmine-api": "*"
    },
    "minimum-stability": "dev"
}

and attempted composer install

The requested package kbsali/redmine-api * could not be found.

Any help would be greatly appreciated. Class seems like it would make my task much easier.

Switch key and value in listing

Hi,

In Version, the listing() function uses the name as key. But the name isn't unique and if you used a name twice or more, only the last is sent back. This also is a problem in Project.

Would it not be better to use the ID as key?

$ret[(int) $e['id']] = $e['name']; 

And for getIdByName()

public function getIdByName($name)
{
  $arr = array_flip($this->listing());

Delete issue version

If you want to remove the target version of an issue, you're supposed to set it to null.
The array_filter call in Redmine\Api\Issue::update removes this null value from the params array, so it never makes it to the rest api call.

New Rest API Features in Redmine 2.2.X

http://www.redmine.org/projects/redmine/wiki/Rest_api

Seems enumerations were added finally for time entries and priories.

Wiki editing but don't see any major upside there.

User Impersonation

As of Redmine 2.2.0, you can impersonate user through the REST API by setting the X-Redmine-Switch-User header of your API request. It must be set to a user login (eg. X-Redmine-Switch-User: jsmith). This only works when using the API with an administrator account, this header will be ignored when using the API with a regular user account.

If the login specified with the X-Redmine-Switch-User header does not exist or is not active, you will receive a 412 error response.

That looks interesting especially in my application since user must set own time spent. =).

This was opened more for thoughts/feedback/suggestions. I will probably implement the stuff above assuming my current redmine projects are still in use.

417 Expectation Fails

when testing using a string for the description of > 2000 characters to a lighttpd server, the curl request would fail in runRequest with header code 417

fixed by adding in $httpHeader[] = 'Expect: ';

perhaps add a client method to specify additional headers?

Strict mode error

Declaration of Redmine\Api\SimpleXMLElement::addChild() should be compatible with SimpleXMLElement::addChild($name, $value = NULL, $ns = NULL)

#70

Create Issue assigned to group

As far as I can see, so far its not possible to create a ticket and assign it to a group instead of a user via 'assigned_to', is there a way so resolve this, maybe going through the group api?
Update: Using 'assigned_to_id' and the group id works, so one would only need to look up the group name for the id.

Guzzle support

Hi. I see guzzle support in current todo list.
I can do that, but i think there is some backward incompatibles.

I will show you my vision of new API

 $httpClient = new \GuzzleHttp\Client([
        'base_url' => 'http://redmine.example.com',
        'defaults' => [
          'auth' => ['michael', 'test']
        ]
  ]);

$client = new \Redmine\Client($httpClient);
# standard api call will not change
$client->api('tracker')->all();

With this aproach we can move all http configuration and loggin (authorization, base url ) to Client

Or there is second way

$httpClient = new \Redmine\HttpClient(); // extends \GuzzleHttp\Client
$httpClient->setBaseUrl('http://redmine.example.com');

$httpClient->setApiKey('jfki478jrba408745'); 
// or 
$httpClient->setUserNameAndPassword('dev_user', '457ffDA'); 

# next code is similar
$client = new \Redmine\Client($httpClient);
# standard api call will not change
$client->api('tracker')->all();

At this point Redmine\Client::runRequest create request, execute it via guzzle client and get response.

Linebreaks

Currently it is not possible to insert line breaks in notes or descriptions.

Example:

{note: "Here comes a linkebreak\r\nwohoo"}

example.php should only do "read only" actions

Ok I admit this was mostly my fault but I configured the top part of the example.php with my Redmine configuration and ran the example.php file without looking at the full code which resulted in it deleting data from my installation. Not exactly the best result when running an example but I think

I suggest example.php.

  • contain read only actions
  • creating/deleting/update actions should be commented so running it won't 'pollute' an existing DB or perhaps example values to be removed (if this was not there, I assuming deletion would all fail resulting in no data lost)

Improve methods to get statistics

Hi guys,

First of all let me thank you for the API. It's really great and easy to use.

I wonder if there is an easy to get statistics only, rather than issues rows. Example:
http://dev.subrion.com/versions/86

You can see this statistics:
Bug 8/20
Feature 3/7

Is there any way to move this type of queries in the default api? Or should I get a list of all issues & then parse them in PHP? Or create separate requests for each datatype I might need (bug - open, bug - closed, feature - open, feature-closed, etc)

Thanks in advance for your time.

assigned_to in Issue.php

Hi,

I´m putting something together to import sheets, but I bumped into this lines {218,222}:

if (isset($params['assigned_to'])) {
            $params['assigned_to'] = $this->client->api('user')->getIdByUsername($params['assigned_to']);
            unset($params['assigned_to']);
        } 

you are unsetting the just created index, I think it hould be assigned_to_id.

Thanks!

Find a project, limit 25

When I search a project with getIdByName, my projects are not found if they are not in the 25 first one.

Indeed "getIdByName" call "listing" function to construct an array of projects.
"Listing" call "all" function because $this->projects is empty and finally "all" function call "retrieveAll" function of AbstractApi.

The problem is that "retrieveAll" function has a default limitation of 25 items so if my project isn't in the first 25 ones it isn't found.

The only way I found for the moment is to call "all" function with a big limit value (200 as I have 160 projects) before calling getIdByName.
But I will need to change this value when I will have more than 200 projects.

Any advice ?

PHP Redmine with Redmine 2.4.0

Hey,

i cant create/update an issue with your api.

Im running an redmine server with version 2.4.0 (released a few days ago).

On the server log i got the following Message in log:

(Update an issue)

Started PUT "/redmine//issues/7518.xml" for 127.0.0.1 at 2013-11-20 08:51:28 +0100
Processing by IssuesController#update as XML
Parameters: {"issue"=>{"id"=>"7518", "author_id"=>"3"}, "id"=>"7518"}
WARNING: Can't verify CSRF token authenticity
API calls must include a proper Content-type header (application/xml or application/json).
Filter chain halted as :verify_authenticity_token rendered or redirected
Completed 422 Unprocessable Entity in 0.0ms (ActiveRecord: 0.0ms)
Started GET "/redmine/issues/7518" for 127.0.0.1 at 2013-11-20 08:51:28 +0100
Processing by IssuesController#show as HTML

Whats going wrong there?

Php Code which im using:

api('issue')->update($id, array( 'assigned_to_id' => $AssignTo, ) ); ``` } ?>

Note: This php code worked with an older version of your API, but it also not working with Redmine 2.4.0

Regards,
Ben

Set Custom Field on User Creation

i have a task to create many users through the rest API. All this Users need to check a Checkbox. So i do this:

Array
(
    [login] => [email protected]
    [firstname] => Klaus
    [lastname] => Peter
    [mail] => [email protected]
    [password] => nqASpKpX
    [cf_10] => 1
)

but nothing happens! The user will be created but the custom field will not be set. I do it like your told in the example.php. The ID from this customfield is 10.

Can you help me?

HTTP response status code

When, for example, I try to get information about issue placed in project I haven't access, I just got "Syntax error" (because redmine response is one space - " "). In this case, we need to get information from curl_getinfo (where response code is 403), but you don't provide this information.
Can you to add support for fetching response code?

Cannot update issue's done_ratio when the given value is zero

Hi,

I'm having a problem with updating an issue, the done_ratio doesn't update when I give the value zero. For example, if the current done_ratio is > 0 and I want to "restart" it, I can't.

This is due to the use of array_filter without a proper callback (it just verifies if the values are == false). I'll send a PR do solve this issue.

get all issues with custom field value.

How to list all issues by searching with custom field value.

when i tried

$issues = $client->api('issue')->all(array(
// 'offset'         => 19,
    'limit'          => 10,
'project_id'     => 'me-proj',
'custom_fields'  => array(
        'id'    => '232',        
        'value' => '1234',
   ),
));

I get this Warning: urlencode() expects parameter 1 to be string, array given in /home/sandeep/public_html/php-redmine-api/lib/Redmine/Api/AbstractApi.php on line 74

Please Help!

Thanks in advance.

Packagist has not the current code

Hi,

It seems that the latest commits from February 28th did not make it to packagist. The latestet version we got via composer misses the namespace fixes.

Best regards
tpinne

Adding multiple issue watchers

Greetings!

I'm currently working on PHP script that imports data into Redmine. I'm having problems with adding watchers to issues.

When providing single integer it works and user is added as a follower to the issue.

$redmine_client->api('issue')->create(array(
       // Other parameters
       'watcher_user_ids' => 5,
));

However, I need to add multiple watchers to the issue. Is it possible to provide an array of integers like so:

$redmine_client->api('issue')->create(array(
       // Other parameters
       'watcher_user_ids' => array(4,5,6),
));

Thanks,
Arthur

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.