Reputation: 508
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
}
}
Upvotes: 0
Views: 759
Reputation: 3440
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...
Upvotes: 0