php-redmine-api icon indicating copy to clipboard operation
php-redmine-api copied to clipboard

Create/Update group with custom_fields

Open hartois opened this issue 4 years ago • 4 comments

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

hartois avatar Apr 05 '21 14:04 hartois

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.

Art4 avatar Apr 05 '21 21:04 Art4

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 avatar Apr 06 '21 11:04 hartois

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

kbsali avatar Apr 06 '21 14:04 kbsali

@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, []);

Art4 avatar Apr 06 '21 20:04 Art4

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.

Art4 avatar Jan 10 '24 15:01 Art4