0

Updating a time entry: http://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Updating-a-time-entry results always in a 404

I'm using Redmine 3.4.6.stable and was using: PUT /time_entries/[id].xml

Other action like: Creating a time entry is working.

Also, Delete is not working and I tried it with JSON as a replacement for XML, but with the same response.

Then I removed the extension like this: /time_entries/[id] and I got a 422, but the response gives me a full HTML page with:

Invalid form authenticity token.

I'm not a Ruby/Rails developer, but in routes.rb I can see:

match '/time_entries/:id', :to => 'timelog#destroy', :via => :delete, :id => /\d+/

This is the only entry for: /time_entries/:id

so this means that the documentation at: http://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Updating-a-time-entry is outdated and there is no end point for updating a time entry. Is this correct?

I also filed a ticket in Redmine: http://www.redmine.org/issues/31288 but I think I'll get here much faster an answer/help.

This is the Groovy code I'm using for updating an issue:

def baseUrl = new URL("${Config.host}/time_entries/${timeEntry.key}.xml?key=${Config.redmineKey}")
new HTTPBuilder(baseUrl).request(Method.PUT, ContentType.XML) {
    body = "<time_entry><id>9956</id><project_id>25</project_id><issue_id>${timeEntry.key}</issue_id><spent_on>${spentOnDate}</spent_on><hours>${new Date(timeEntry.value.toInteger()).format("HH:mm")}</hours><activity_id>9</activity_id><comments></comments></time_entry>"
    response.success = { resp, xml ->
        println "Success! ${resp.status}"
    }
    response.failure = { resp ->
        println "Request failed with status ${resp.status}"
        def outputStream = new ByteArrayOutputStream()
        resp.entity.writeTo(outputStream)
        def errorMsg = outputStream.toString('utf8')
        println errorMsg
    }
}
occurred
  • 490
  • 1
  • 5
  • 13

1 Answers1

0

below code works with nodejs and uses xml format:

const http = require('http')

var body = ' <?xml version="1.0" ?>' +
           '<time_entry><id>1</id><issue_id>1</issue_id><spent_on>2019-02-02</spent_on><hours>9.0</hours></time_entry>';

var postRequest = {
    host: "localhost",
    path: "/time_entries/1.xml",
    port: 3000,
    method: "PUT",
    headers: {
        'Content-Type': 'text/xml',
        'X-Redmine-API-Key': '95228de814b46d8980447c00591460598990d469',
        'Content-Length': Buffer.byteLength(body)
    }
};

var buffer = "";

var req = http.request( postRequest, function( res )    {

   console.log( res.statusCode );
   var buffer = "";
   res.on( "data", function( data ) { buffer = buffer + data; } );
   res.on( "end", function( data ) { console.log( buffer ); } );

});

req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
});

req.write( body );
req.end();

Make sure to configure postRequest parameters correctly, like X-Redmine-API-key path, host, port and method...

Aleksandar Pavić
  • 3,143
  • 1
  • 34
  • 36
  • I'm using Redmine 3.4.6.stable and there it seems it is not implemented. Can you please check there also? – occurred May 16 '19 at 14:37
  • My version is: 3.4.6.stable.17600 – Aleksandar Pavić May 17 '19 at 06:00
  • Also I've just replaced PUT to DELETE and it deleted entry... Please post your full code somewhere for additional bug identification... – Aleksandar Pavić May 17 '19 at 06:39
  • I think that the problem is with ?key, not sure about code in groovy, but in nodejs code, you can see X-Redmine-API-Key as header reqest value... Probably something like import com.eviware.soapui.support.types.StringToStringMap def headers = new StringToStringMap() headers.put("X-Redmine-API-Key","value") testRunner.testCase.getTestStepByName("REST Test Request").testRequest.setRequestHeaders(headers) – Aleksandar Pavić May 21 '19 at 06:48
  • I've tried it also with the headers, but also getting 404. For inserting a time entry it works with the URL parameter, so this seems to be fine. I really think that in my version the route is missing. Can you please have a look if in your version the route is defined for it? – occurred May 22 '19 at 07:25