Project

General

Profile

Actions

Defect #34212

closed

Time Entries POST doesn't work in JSON format

Added by Robert Roth almost 4 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
REST API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Invalid
Affected version:

Description

Environment

fairly stock Redmine 4.1.1, in a docker environment.


  Redmine version                4.1.1.stable
  Ruby version                   2.6.6-p146 (2020-03-31) [x86_64-linux-musl]
  Rails version                  5.2.4.2
  Environment                    production
  Database adapter               SQLite
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
SCM:
  Subversion                     1.12.2
  Mercurial                      5.3.2
  Bazaar                         2.7.0
  Git                            2.24.3
  Filesystem                     
Redmine plugins:
  no plugin installed

Steps to reproduce

  1. create a first redmine project
  2. create a simple issue
  3. allow API access
  4. try to POST to /time_entries.xml with Content-Type application/xml
    <time_entry>
        <project_id>1</project_id>
        <issue_id>1</issue_id>
        <user_id>1</user_id>
        <hours>2.0</hours>
        <comments>Additional implementation</comments>
        <spent_on>2020-10-28</spent_on>    
    </time_entry>
    
  5. try to POST the same data in JSON to /time_entries.json with Content-Type application/json
    {
        "project_id":"1",
        "issue_id":"1",
        "user_id":"1",
        "hours":"2.0",
        "comments":"Additional implementation",
        "spent_on":"2020-10-28" 
    }
    
  6. try to POST the same data but with hours formatted as number to /time_entries.json with Content-Type application/json
    {
        "project_id":"1",
        "issue_id":"1",
        "user_id":"1",
        "hours":2.0,
        "comments":"Additional implementation",
        "spent_on":"2020-10-28" 
    }
    

What happens

in step 4, XML format, the time entry is created, returns with http 201
in step 5 and 6, JSON format, the endpoint returns with 422 Unprocessable Entity, complaining about

{
    "errors": [
        "Hours cannot be blank" 
    ]
}

Expected result

either step 5 or step 6 (or maybe both) should work, to be able to create a time entry using JSON-based REST API

Actions #1

Updated by florent thiery almost 4 years ago

Same problem here

Note that the wiki says that project_id or issue_id is required, not both (i'm not sure it's correct)

https://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Creating-a-time-entry

Actions #2

Updated by Robert Roth almost 4 years ago

florent thiery wrote:

Same problem here

Note that the wiki says that project_id or issue_id is required, not both (i'm not sure it's correct)

https://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Creating-a-time-entry

That seems perfectly correct, as an issue exists in the context of a project, if you have an issueId, you can find the project easily. And you can log time on project without specifying an issueId, so yes, either one or the other is required. However, it works fine if you specify both values.

Actions #3

Updated by florent thiery almost 4 years ago

Thanks for the precision, i was not aware that you could fill time on a project. I think the wiki should be updated to reflect the possibility of passing user_id

EDIT: i just did it actually

Actions #4

Updated by adahox dias over 1 year ago

the right way to do it is:

{
    "time_entry": {
        "project_id": "1",
        "issue_id": "1",
        "user_id": "1",
        "hours": "2.0",
        "comments": "Additional implementation",
        "spent_on": "2020-10-28" 
    }
}
Actions #5

Updated by Holger Just about 1 year ago

  • Status changed from New to Closed
  • Resolution set to Invalid
Actions

Also available in: Atom PDF