kbsali / php-redmine-api

A simple PHP Redmine API client, Object Oriented

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create/Update group with custom_fields

hartois opened this issue · comments

Hello, please add feature for setting custom_fields in Group on create/update such as in User

Hey, this feature has no details in Redmine documentation: http://www.redmine.org/projects/redmine/wiki/Rest_Groups#PUT

If someone can figure out how the API works we would be happy about more information or a PR.

It's work same as in User:
curl -H "Content-Type: application/json" -X POST -H 'X-Redmine-API-Key: <API_KEY>' --data-raw '{"group":{"name":"test3","custom_fields":[{"id":2,"value":"testvalue"}]}}' http://redmine.local/groups.json

will create group with custom field of id 2, value - "testvalue"

@hartois if it is similar to the User API, how about proposing a pull request with the changes you are after? :)
Thanks!

@hartois You can start with extending the Group class and implement the missing feature. If you are sure that it works you can post it here or create a pull request and we will be happy to merge it.

class GroupApi extends \Redmine\Api\Group
{
    public function update($id, array $params = [])
    {
        // Build your implmeentation here
        return $this->put('/groups/'.$id.'.xml', $body);
    }
}

// try using it
$groupApi = new GroupApi($redmineClient);
$return = $groupApi->update(12, []);

Creating a group with custom_fields is already possible:

$client->getApi('group')->create([
    'name' => 'asdf',
    'user_ids' => [1, 2],
    'custom_fields' => [
        [
            'id' => 123,
            'name' => 'cf_name',
            'value' => 'cf_value',
        ],
    ],
]);

I will update the docs and working at the feature to updating groups and custom_fields.