Skip to content

XML/JSON parameter mismatch in TimeEntry.php #401

@LPRKR

Description

@LPRKR

Hello!
Using the 2.6.0 API on PHP 8.2.
Creating a time entry works, but results in error messages like this:

Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in vendor\kbsali\redmine-api\src\Redmine\Api\TimeEntry.php on line 146

Warning: SimpleXMLElement::__construct(): {"log_type":"T","id":430626,"hours":3.0,"comments":"automated entry","spent_on in vendor\kbsali\redmine-api\src\Redmine\Api\TimeEntry.php on line 146

Warning: SimpleXMLElement::__construct(): ^ in vendor\kbsali\redmine-api\src\Redmine\Api\TimeEntry.php on line 146

Fatal error: Uncaught Exception: String could not be parsed as XML in vendor\kbsali\redmine-api\src\Redmine\Api\TimeEntry.php:146 Stack trace: #0 vendor\kbsali\redmine-api\src\Redmine\Api\TimeEntry.php(146): SimpleXMLElement->__construct('{"log_type":"T"...') #1 get_users.php(52): Redmine\Api\TimeEntry->create(Array) #2 {main} thrown in vendor\kbsali\redmine-api\src\Redmine\Api\TimeEntry.php on line 146

After a quick source code lookup, it tries to parse this exact string as XML in ->create() method by "return new SimpleXMLElement($body);", which is a JSON, not XML.

{"log_type":"T","id":430626,"hours":3.0,"comments":"automated entry","spent_on":"2024-06-14","project":{"id":4506},"issue":{"id":55757},"activity":{"id":53},"user":{"id":3094},"spentFor":{"id":150199,"start_on":"2024-06-14T00:00:00.000Z","end_on":null,"clock_action":null}} 

I am using this code to create a time entry:

$create_time_entry_result = $client->getApi('time_entry')->create([
    'project_id' => 4506,
    'issue_id' => 55757,
    'spent_on' => '2024-06-14',
    'hours' => 3,
    'activity_id' => 53,
    'comments' => 'automated entry'
]);

Seems like an API error, could I ask for a fix? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    possible bugIssue is possibly a bug, needs investigation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions