Using REST API for custom fields

Added by Thomas Spycher over 7 years ago

Hi,
i'm currently developing a Plugin for Wordpress which should integrate redmine in it. The Plugin should be able to create issues. This is working very well. But i cant get the custom fields to work.
How sould a request XML look like to add a custom field to a new Issue?!

Thanks a looot for your help!

Replies (15)

RE: Using REST API for custom fields - Added by Emil Ek over 7 years ago

Hello!

I did get the following xml to be valid and adding a cusom field:

<issue>
<project_id>1</project_id>
<tracker_id>1</tracker_id>
<subject>test2</subject>
<description>desc1gsdfgsdg</description>
<custom_field_values>
<1>test</1>
</custom_field_values>
</issue>

And then posted the XML file to in my case http://localhost/redmine2/issues.xml?format=xml

Regards Emil

RE: Using REST API for custom fields - Added by Thomas Spycher over 7 years ago

Thanks for your answer... I'm still getting the following Error Message:

HTTP/1.1 422 Unprocessable Entity
Date: Sat, 04 Sep 2010 10:08:10 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 PHP/5.3.2 SVN/1.6.5 mod_python/3.3.1 Python/2.6.1 Phusion_Passenger/2.2.15
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
X-Runtime: 30
Cache-Control: no-cache
Set-Cookie: _redmine_session=**************; path=/; HttpOnly
Content-Length: 185
Status: 422
Cache-Control: max-age=60
Expires: Sat, 04 Sep 2010 10:09:10 GMT
MS-Author-Via: DAV
Content-Type: application/xml; charset=utf-8
<errors>
<error>Customer Name can't be blank</error>
<error>Customer EMail can't be blank</error>
<error>Value is invalid</error>
</errors>

What do the tag <1> stand for? The ID of the Custom Field?

RE: Using REST API for custom fields - Added by James Bernard over 7 years ago

Thomas Spycher wrote:

What do the tag <1> stand for? The ID of the Custom Field?

Yes, that's the custom field ID.

The response shows 3 errors:
  • did you provide a value for "customer name" and "customer email" fields (I guess they are defined as "required")
  • is the value you provide valid for the target custom field (belonging to list of possible values for list type, matching validation rules, ...)

RE: Using REST API for custom fields - Added by Thomas Spycher over 7 years ago

"customer name" and "customer email" do have the id's 1 and two and i provided them in the xml and still get the error message. Yes, the both custom fields are required...

RE: Using REST API for custom fields - Added by James Bernard over 7 years ago

OK, so the values you provided are probably not accepted.

Of which type (list, text, ...) are your two CF ?

Did you define a RegExp for values validation ? If yes, do the values you provide match this RegExp ?

RE: Using REST API for custom fields - Added by Thomas Spycher over 7 years ago

I left the regex field empty. And the type is text...

I just did an "svn update" on the server to get the latest revision. Now, apache wont start anymore ;-) After fixing it, i can post some screenshots if you like...

RE: Using REST API for custom fields - Added by James Bernard over 7 years ago

Yes, please provide a snapshot of custom fields definition page and also your xml data.

Good luck for restarting your apache :o)

RE: Using REST API for custom fields - Added by Thomas Spycher over 7 years ago

Haha... Thank you :) Finally i've restarted it...

Attached the Screenshot of one field. The second has the same config.

Man, thank you for your help!

RE: Using REST API for custom fields - Added by James Bernard over 7 years ago

Thanks for the snapshot.

Could you post the xml data you send as well ;o) If you cannot catch it at the source (in your plugin), you can copy/paste the received data from redmine log, in the XML request dump.

RE: Using REST API for custom fields - Added by Thomas Spycher over 7 years ago

:)

here is the XML Request:

<issue>
<key>123456789</key>
<subject>I am a Test</subject>
<description>This is the description</description>
<project_id>6</project_id>
<tracker_id>3</tracker_id>
<custom_field_values>
<1>customername</1>
<2>customermail</2>
</custom_field_values>
</issue>

RE: Using REST API for custom fields - Added by James Bernard over 7 years ago

Well, your XML looks good, the custom fields settings as well, it should work...
Which redmine version do you run ? Is it the trunk (which revision) ? Do you use some plugins ?

RE: Using REST API for custom fields - Added by Thomas Spycher over 7 years ago

No plugins, current trunk...

RE: Using REST API for custom fields - Added by Florent Fievez over 7 years ago

<issue>
<key>123456789</key>
<subject>I am a Test</subject>
<description>This is the description</description>
<project_id>6</project_id>
<tracker_id>3</tracker_id>
<custom_field_values>
<1>customername</1>
<2>customermail</2>
</custom_field_values>
</issue>

Is there other way to specify custom_field_values ? Because XML DOM doesn't accept <1> <2> tags, indeed this is not support by XML norm !

RE: Using REST API for custom fields - Added by Florent Fievez over 7 years ago

Florent Fievez wrote:

[...]

Is there other way to specify custom_field_values ? Because XML DOM doesn't accept <1> <2> tags, indeed this is not support by XML norm !

Right now, I just used a workaround :

$aElem = $aXmlDoc->createElement("_TOREMOVE_1");
(...)
$aXmlOut = str_replace("_TOREMOVE_","",$aXmlDoc->saveXML($aRoot));

But this sucks ...

(1-15/15)