Fields not updated through REST API
Added by Peter Carlsson over 13 years ago
I am trying to updated an issue and some custom fields through the REST API (using REBOL).
I read the current issue data:
GET /issues.xml?key='ValidApiKey'&issue_id=122&include=journals HTTP/1.0
Then I modify the response to update the custom field ToDoNextStep and then send the follwing:
PUT /issues/122.xml?key='ValidApiKey' HTTP/1.0 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?><issue><id>122</id><project name="ToDo" id="2"/><tracker name="Support" id="3"/><status name="Ny" id="1"/><priority name="Normal" id="4"/><author name="Peter Carlsson" id="3"/><assigned_to name="Peter Carlsson" id="3"/><category name="REBOL" id="5"/><subject>Testar integrering med REBOL</subject><description>Kommer att användas för att testa att läsa och uppdatera från REBOL.</description><start_date>2011-03-30</start_date><due_date></due_date><done_ratio>0</done_ratio><estimated_hours></estimated_hours><custom_fields type="array"><custom_field name="ToDoState" id="1"><value>New</value></custom_field><custom_field name="ToDoNextStep" id="2"><value>Waiting</value></custom_field></custom_fields><created_on>2011-03-30T15:32:16+02:00</created_on><updated_on>2011-04-13T14:46:44+02:00</updated_on></issue>}
With log level set to DEBUG I get:
Processing IssuesController#update to xml (for 1.2.3.4 at 2011-04-13 13:53:53) [PUT] Parameters: {"format"=>"xml", "action"=>"update", "id"=>"122", "controller"=>"issues", "key"=>"ValidApiKey"} SQL (1.0ms) SELECT max(`settings`.updated_on) AS max_updated_on FROM `settings` Token Load (1.3ms) SELECT * FROM `tokens` WHERE (`tokens`.`value` = 'ValidApiKey' AND `tokens`.`action` = 'api') LIMIT 1 User Load (16.6ms) SELECT * FROM `users` WHERE (`users`.`id` = 3) AND ( (`users`.`type` = 'User' OR `users`.`type` = 'AnonymousUser' ) ) Issue Load (3.1ms) SELECT * FROM `issues` WHERE (`issues`.`id` = 122) Project Load (5.0ms) SELECT * FROM `projects` WHERE (`projects`.`id` = 2) Tracker Load (0.4ms) SELECT * FROM `trackers` WHERE (`trackers`.`id` = 3) IssueStatus Load (7.1ms) SELECT * FROM `issue_statuses` WHERE (`issue_statuses`.`id` = 1) CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 3) AND ( (`users`.`type` = 'User' OR `users`.`type` = 'AnonymousUser' ) ) IssuePriority Load (2.3ms) SELECT * FROM `enumerations` WHERE (`enumerations`.`id` = 4) AND ( (`enumerations`.`type` = 'IssuePriority' ) ) IssueCategory Load (0.6ms) SELECT * FROM `issue_categories` WHERE (`issue_categories`.`id` = 5) EnabledModule Load (0.6ms) SELECT name FROM `enabled_modules` WHERE (`enabled_modules`.project_id = 2) EnabledModule Columns (3.9ms) SHOW FIELDS FROM `enabled_modules` Member Columns (4.0ms) SHOW FIELDS FROM `members` Member Load Including Associations (0.8ms) SELECT `members`.`id` AS t0_r0, `members`.`user_id` AS t0_r1, `members`.`project_id` AS t0_r2, `members`.`created_on` AS t0_r3, `members`.`mail_notification` AS t0_r4, `projects`.`id` AS t1_r0, `projects`.`name` AS t1_r1, `projects`.`description` AS t1_r2, `projects`.`homepage` AS t1_r3, `projects`.`is_public` AS t1_r4, `projects`.`parent_id` AS t1_r5, `projects`.`created_on` AS t1_r6, `projects`.`updated_on` AS t1_r7, `projects`.`identifier` AS t1_r8, `projects`.`status` AS t1_r9, `projects`.`lft` AS t1_r10, `projects`.`rgt` AS t1_r11, `roles`.`id` AS t2_r0, `roles`.`name` AS t2_r1, `roles`.`position` AS t2_r2, `roles`.`assignable` AS t2_r3, `roles`.`builtin` AS t2_r4, `roles`.`permissions` AS t2_r5 FROM `members` LEFT OUTER JOIN `projects` ON `projects`.id = `members`.project_id LEFT OUTER JOIN `member_roles` ON (`members`.`id` = `member_roles`.`member_id`) LEFT OUTER JOIN `roles` ON (`roles`.`id` = `member_roles`.`role_id`) WHERE (`members`.user_id = 3 AND (projects.status=1)) ORDER BY projects.name Workflow Load (0.6ms) SELECT * FROM `workflows` WHERE (`workflows`.old_status_id = 1 AND (`workflows`.`role_id` IN (3) AND `workflows`.`tracker_id` = 3)) Workflow Columns (6.8ms) SHOW FIELDS FROM `workflows` IssueStatus Load (0.6ms) SELECT * FROM `issue_statuses` WHERE (`issue_statuses`.`id` IN (6,2,3,4,5)) IssueRelation Load (0.6ms) SELECT * FROM `issue_relations` WHERE (`issue_relations`.issue_to_id = 122) IssuePriority Load (0.6ms) SELECT * FROM `enumerations` WHERE ( (`enumerations`.`type` = 'IssuePriority' ) ) ORDER BY enumerations.position ASC TimeEntry Columns (4.7ms) SHOW FIELDS FROM `time_entries` TimeEntryActivity Columns (9.7ms) SHOW FIELDS FROM `enumerations` TimeEntryActivity Load (10.0ms) SELECT * FROM `enumerations` WHERE (`enumerations`.`is_default` = 1) AND ( (`enumerations`.`type` = 'TimeEntryActivity' ) ) ORDER BY enumerations.position ASC LIMIT 1 Journal Columns (6.6ms) SHOW FIELDS FROM `journals` IssueStatus Load (3.4ms) SELECT * FROM `issue_statuses` WHERE (`issue_statuses`.`id` = 0) IssueStatus Load (3.8ms) SELECT * FROM `issue_statuses` WHERE (is_default=1) LIMIT 1 IssuePriority Load (0.9ms) SELECT * FROM `enumerations` WHERE (`enumerations`.`id` = 0) AND ( (`enumerations`.`type` = 'IssuePriority' ) ) ORDER BY enumerations.position ASC IssuePriority Load (0.9ms) SELECT * FROM `enumerations` WHERE (`enumerations`.`is_default` = 1) AND ( (`enumerations`.`type` = 'IssuePriority' ) ) ORDER BY enumerations.position ASC LIMIT 1 CustomValue Load Including Associations (1.3ms) SELECT `custom_values`.`id` AS t0_r0, `custom_values`.`customized_type` AS t0_r1, `custom_values`.`customized_id` AS t0_r2, `custom_values`.`custom_field_id` AS t0_r3, `custom_values`.`value` AS t0_r4, `custom_fields`.`id` AS t1_r0, `custom_fields`.`type` AS t1_r1, `custom_fields`.`name` AS t1_r2, `custom_fields`.`field_format` AS t1_r3, `custom_fields`.`possible_values` AS t1_r4, `custom_fields`.`regexp` AS t1_r5, `custom_fields`.`min_length` AS t1_r6, `custom_fields`.`max_length` AS t1_r7, `custom_fields`.`is_required` AS t1_r8, `custom_fields`.`is_for_all` AS t1_r9, `custom_fields`.`is_filter` AS t1_r10, `custom_fields`.`position` AS t1_r11, `custom_fields`.`searchable` AS t1_r12, `custom_fields`.`default_value` AS t1_r13, `custom_fields`.`editable` AS t1_r14, `custom_fields`.`visible` AS t1_r15 FROM `custom_values` LEFT OUTER JOIN `custom_fields` ON `custom_fields`.id = `custom_values`.custom_field_id WHERE (`custom_values`.customized_id = 122 AND `custom_values`.customized_type = 'Issue') ORDER BY custom_fields.position SQL (0.8ms) BEGIN Issue Load (4.6ms) SELECT * FROM `issues` WHERE (((issues.id != 122) AND (issues.`lft` <= 1 AND issues.`rgt` >= 2)) AND (`issues`.`root_id` = 122)) ORDER BY `lft` CACHE (0.0ms) SELECT * FROM `issues` WHERE (((issues.id != 122) AND (issues.`lft` <= 1 AND issues.`rgt` >= 2)) AND (`issues`.`root_id` = 122)) ORDER BY `lft` Issue Update with optimistic locking (4.9ms) UPDATE `issues` SET `lock_version` = 35, `updated_on` = '2011-04-13 13:53:54' WHERE id = 122 AND `lock_version` = 34 IssueCustomField Load (1.0ms) SELECT * FROM `custom_fields` WHERE (is_for_all=1) AND ( (`custom_fields`.`type` = 'IssueCustomField' ) ) ORDER BY position IssueCustomField Load (1.1ms) SELECT * FROM `custom_fields` INNER JOIN `custom_fields_projects` ON `custom_fields`.id = `custom_fields_projects`.custom_field_id WHERE (`custom_fields_projects`.project_id = 2 ) AND ( (`custom_fields`.`type` = 'IssueCustomField' ) ) ORDER BY custom_fields.position IssueCustomField Load (1.2ms) SELECT `custom_fields`.id FROM `custom_fields` INNER JOIN `custom_fields_trackers` ON `custom_fields`.id = `custom_fields_trackers`.custom_field_id WHERE (`custom_fields`.`id` = 1) AND (`custom_fields_trackers`.tracker_id = 3 ) AND ( (`custom_fields`.`type` = 'IssueCustomField' ) ) LIMIT 1 IssueCustomField Load (1.2ms) SELECT `custom_fields`.id FROM `custom_fields` INNER JOIN `custom_fields_trackers` ON `custom_fields`.id = `custom_fields_trackers`.custom_field_id WHERE (`custom_fields`.`id` = 2) AND (`custom_fields_trackers`.tracker_id = 3 ) AND ( (`custom_fields`.`type` = 'IssueCustomField' ) ) LIMIT 1 IssueStatus Load (1.0ms) SELECT * FROM `issue_statuses` WHERE (`issue_statuses`.`id` = 0) IssueStatus Load (0.9ms) SELECT * FROM `issue_statuses` WHERE (is_default=1) LIMIT 1 IssuePriority Load (0.9ms) SELECT * FROM `enumerations` WHERE (`enumerations`.`id` = 0) AND ( (`enumerations`.`type` = 'IssuePriority' ) ) ORDER BY enumerations.position ASC IssuePriority Load (0.9ms) SELECT * FROM `enumerations` WHERE (`enumerations`.`is_default` = 1) AND ( (`enumerations`.`type` = 'IssuePriority' ) ) ORDER BY enumerations.position ASC LIMIT 1 SQL (4.9ms) COMMIT Completed in 872ms (View: 1, DB: 120) | 200 OK [http://server.hemma/issues/122.xml?key='ValidApiKey']
The custom field does not change but the updated_on field indicates that the issue was updated.
As far as I know the user have sufficient permissions.
Do I do something wrong? Any help would be appreciated.
Best regards,
Peter Carlsson
Replies (2)
RE: Fields not updated through REST API
-
Added by Peter Carlsson over 13 years ago
Maybe I scared some people off by saying I was using REBOL...
Although I get a 200 OK response I tried the same thing from the web, logged in as the same user I used the ValidApiKey from. It seems that there are more steps involved when updating an issue than just the one I do. Do I need to do several HTTP PUT calls to update an issue and what should I send?
Best regards,
Peter Carlsson
RE: Fields not updated through REST API
-
Added by Peter Carlsson over 13 years ago
I have now tried the same steps but using JSON instead of XML. The result is the same. The value of the field to change stays the unchanged, but the updated_on field is set to current date/time.
The question is if I am doing anything wrong? Is there an easy way to debug what is happening since I am not that familiar with Ruby?
Any help would be extremely appreciated.
Best regards,
Peter Carlsson