How To Update Issue via REST?
Added by Anonymous over 15 years ago
HI guys,
I'm currently developing on an Integration of Redmine to our Release-System. Can anyone tell me how I can update the status of an issue with JavaScript and REST? I tried it with jQuery, but always getting a 405 Method not allowed error. I know Rails is using the paramater _method to identify which method actually to use. But how can I integrate this parameter in the xml document I will sent to the server?
Thanks a lot!
Regards,
Martin
Replies (4)
RE: How To Update Issue via REST?
-
Added by Felix Schäfer over 15 years ago
I think _method identifies the HTTP Verb used for the request.
RE: How To Update Issue via REST?
-
Added by Anonymous over 15 years ago
Hi,
yes I already know, but how can I put this variable in the request? My jQuery-call looks like this:
$.ajax({
url: repositoryURL + "/issues/" + issueID + ".xml",
async: false,
type: 'POST',
contentType: "text/xml",
username: redmineUser,
password: redminePass,
data: issueXml,
success: function(msg) {
alert(msg);
},
error: function(request, msg, error) {
alert(error);
}
});
I put the data containing the updated fields as XML in data. So, where should I place _method now?
Thanks a lot!
Regards,
Martin
RE: How To Update Issue via REST?
-
Added by Anonymous over 15 years ago
I found the solution. I wanted to update the status, so my data looked like this:
" ... ?><issue><id>123</id><status id="3" /></issue>"
But this is not correct! To update the status Redmine expects a field "status_id" containing the new status. So my new XML looks like this:
" ... ?><issue><id>123</id><status_id>3</status_id></issue>".
You're right that "_method" identifies the HTTP verb used, but when I try to POST the data including the parameter "_method" I always get the 405 HTTP error. So I tried to change "type: 'POST'" to "type: 'PUT'" in my jQuery ajax call and now it works!
My final ajax call looks like this:
jQuery.ajax({
type: "PUT",
url: redmineURL,
username: redmineUser,
password: redminePass,
async: false,
contentType: "text/xml",
data: "xml",
data: '<?xml version="1.0" encoding="UTF-8"?><issue><id>' + ticketId + '</id><status_id> + newStatus + '</status_id></issue>',
success: function(msg) {
alert("success");
},
error: function(xhr, msg, error) {
alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
alert("responseText: "+xhr.responseText);
}
});
The funny thing is, jQuery gets an error, but the error says that the request was complete and the given HTTP Status is 200 ;) I don't know why jQuery gets an error and does not call the success function although it gets an 200 HTTP return code and an xhr status of 4 (complete).
Regards,
Martin
RE: How To Update Issue via REST? ADD X-Redmine-API-Key
-
Added by Gökhan Karaca almost 14 years ago
Update your function.
"beforeSend" method is implemented to jQuery > 1.5
Add code to you ajax call:
ticketData = '<?xml version="1.0" encoding="UTF-8"?>';
ticketData += '<issue>';
ticketData += '<id>' + ticketId + '</id>';
ticketData += '<status_id>' + Settings.redmineStatus + '</status_id>';
ticketData += '</issue>';
jQuery.ajax({
type: "PUT",
url: redmineURL,
crossDomain: true,
username: redmineUser,
password: redminePass,
async: false,
contentType: "application/xml",
data: ticketData,
beforeSend: function(xhr) {
xhr.setRequestHeader('X-Redmine-API-Key', 'ADD_YOUR_API_KEY_HERE');
},
success: function(msg) {},
error: function(xhr, msg, error) {}
});
Do not forget the right workflow!!!