Is it possible to retrieve a specific history entry from the work item through the REST API?
There is a tool built client using RTC REST API. This tool retrieves the work items from a given time frame and records them in an external database. It is required to retrieve the work item history along with some other attributes.
Whenever a work item is retrieved, history is comprised of all entries.
The question is: is it possible to retrieve a specific history entry? What we want to achieve is a delta update in the work item history in the external database. So let's say a work item has 10 history entries. Through the tool, the work item gets recorded in the external database. After that, the work item was changed, and a 11th history entry was created in RTC. We are able to update the work item in the external database, but instead of recording all history entries over again, we want to record only the 11th history entry. Is this possible to achieve through the REST API?
Accepted answer
"itemHistory (type: com.ibm.team.workitem.WorkItem, maxOccurs: unbounded). A collection of zero or more WorkItem elements, representing the entire history of the work item. Each state the work item has ever been in is reflected in this history list. "
This means you should be able to perform the same filtering mechanisms on the historic versions of the workitem as you can on the current version. Sure enough a query such as the one below will only return the itemHistory records modified since 2014-05-01. You can use this mechanism to create a "delta" pull for your external repository, only pulling itemHistory records that have been created since your last pull.
https://<server:port>/ccm/rpt/repository/workitem?fields=workitem/workItem/itemHistory[modified > 2014-05-01T01:00:00.000-0500]/*/*/*
One other answer
Comments
Do you have any record which were modified on or after this date? In my experience, if there aren't any records matching, you would always get an empty <workItem />
I see similar behavior. I'm not sure why the API returns those empty <workItem/> tags when you filter on itemHistory in this fashion. You likely have a paged result set though. If you traverse the "next" links given in your response do any of them contain data? The other thing you could try is to filter at the workItem level as well:
https://<server:port>/ccm/rpt/repository/workitem?fields=workitem/workItem[modified > 2014-09-11T10:00:28.000-0000]/itemHistory[modified > 2014-09-11T10:00:28.000-0000]/*
Thank you both for your quick responses! Karthik, there were hundreds of WIs modified after that date. If there were none, in my experience it doesn't return any elements at all. And Brian, I tried iterating through the many next pages and I got the same response throughout all of the pages.
Actually, one extra question. Is it possible to get, within the same query, fields from the Work Item in addition to fields in itemHistory? For example, finding the latest state ID of the Work Item so that I can verify which Item History element is the current one.