Reputation: 809
I need a script to insert new Issues into redmine. It will have more complicated features in the end but for now that's all I'm trying to accomplish. I've used the sample used on their website: http://www.redmine.org/projects/redmine/wiki/Rest_api_with_php The second one using ActiveResource. It works well, but if I try adding custom fields it doesn't work. I'm pretty new to PHP but completely new to redmine and working with this type of stuff. Would it be possible to add the custom field? This is the code used currently:
<?php
require_once ('ActiveResource.php');
class Issue extends ActiveResource {
var $site = 'http://username:password@website/';
var $request_format = 'xml'; // REQUIRED!
}
// create a new issue
$issue = new Issue (array ('subject' => 'XML REST API2', 'project_id' => '6'));
$issue->save ();
echo $issue->id;
?>
I have tried to add a new Issue into my project without using the script, and that's how the XML file for that issue with a custom field called Ad ID looks like:
<issue>
<id>17</id>
<project id="7" name="test 1"/>
<tracker id="1" name="Bug"/>
<status id="1" name="New"/>
<priority id="2" name="Normal"/>
<author id="1" name="Redmine Admin"/>
<subject>XML REST API2</subject>
<description/>
<start_date>2014-06-13</start_date>
<due_date/>
<done_ratio>0</done_ratio>
<estimated_hours/>
<custom_fields type="array">
<custom_field id="1" name="Ad ID">
<value>43434</value>
</custom_field>
</custom_fields>
<created_on>2014-06-13T17:28:53Z</created_on>
<updated_on>2014-06-13T17:29:51Z</updated_on>
</issue>
Is there a simple way to include custom fields in my script?
Edit: I have tried something like this and it doesn't work, it doesn't create a new issue at all.
$issue = new Issue (array ('subject' => 'XML REST API222', 'project_id' => '6', 'custom_fields' => array(
array(
'id' => 1,
'name' => 'Ad ID',
'value' => '7427'
))));
Upvotes: 1
Views: 1974
Reputation: 809
I found the answer to my own question. For those who had the same issue, here is how you include custom fields:
'custom_fields' => array('@type' => "array",
'custom_field' => array('@id' => '1',
array('value' => '234'))
)));
Upvotes: 1