Project

General

Profile

REST API json/xml syntax for updating/creating issues

Added by Matt Wheaton over 13 years ago

I'm trying to figure out the syntax for updating an issue via the REST API. In my case, I'm trying to update the custom fields via JSON, specifically an integer field named "Order". Unfortunately, the Rest_Issues wiki page doesn't include this information, or at least it isn't very obvious, and I haven't been able to find the information anywhere else.

Using curl and Redmine 1.1.1, my attempts so far include:

PUT /issues/8.json
{"issue":{"custom_fields":[{"id":"4","name":"Order","value":5}]},"key":"..."}
...
HTTP/1.1 422 Unprocessable Entity
{"errors":[["custom_values","is invalid"]]}

Another attempt:
PUT /issues/8.json
{"issue":{"custom_values":[{"id":"4","name":"Order","value":5}]},"key":"..."}
...
HTTP/1.1 200 OK
however, the custom field is not updated. I also got the same response when I replaced "custom_values" with "blahblahblah".

After looking at the code (source:/tags/1.1.1/app/views/issues/index.api.rsb#L22 and source:/tags/1.1.1/app/helpers/custom_fields_helper.rb#L109), I tried:

PUT /issues/8.json
{"issue":{"custom_field_values":[{"custom_field_id":"4","custom_field":{"name":"Order"},"value":5}]},"key":"..."}
...
HTTP/1.1 500 Internal Server Error
... please contact your redMine administrator for assistance ...

I'm not sure if this is a bug or not, but either way, I think the Rest_Issues page could use more complete information.

Has anyone been successful in updating custom fields using the API?


Replies (4)

RE: REST API json/xml syntax for updating/creating issues - Added by Etienne Massip over 13 years ago

I didn't try yet, but someone else has filled an issue for your concern : #8195.

RE: REST API json/xml syntax for updating/creating issues - Added by Etienne Massip over 13 years ago

Not sure this is related, though, as he was trying to create an issue, not update it.

RE: REST API json/xml syntax for updating/creating issues - Added by Matt Wheaton over 13 years ago

It's essentially the same thing I'm looking for, I imagine the POST and PUT syntax would be more or less the same.

After more trial & error, with the help of the debug logging, I stumbled upon this solution:

PUT /issues/8.json
{"issue":{"custom_field_values":{"<custom_field_id>":"<new_value>",...}},"key":"..."}

RE: REST API json/xml syntax for updating/creating issues - Added by Curtis Weatherford almost 7 years ago

Is there a more detail description of this somewhere? I'm having a bear of time trying to update a ticket using PUT and I seem to have the same issue you were having.

    (1-4/4)