Project

General

Profile

Actions

Defect #34212

closed

Time Entries POST doesn't work in JSON format

Added by Robert Roth about 4 years ago. Updated over 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

Also available in: Atom PDF