It's all about the answers!

Ask a question

Change WorkItem State via REST


0
1
Erik Vonderheid (461) | asked Mar 10 '10, 6:01 a.m.
Hi,

I'm using RTC 2.0.0.2 Standard Edition and I'm trying to change the state of a WorkItem via REST.

REST URL:

https://lap-ibm-853.psad.de:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/28

JSON:

{"dc:identifier":28,
"rtc_cm:state":{
"rdf:resource":
"https:\/\/LAP-IBM-853.PSAD.de:9443\
/jazz\/oslc\/workflows\/_Wp0-gCeREd-nSqqeCWspMA\
/states\/bugzillaWorkflow\/5"
},
...


I'm using a org.apache.http.client.methods.HttpPut against the URL with the JSON as org.apache.http.entity.StringEntity.

The response is a 400: Bad Request.

All I want to do is change the state from
resolved

https://LAP-IBM-853.PSAD.de:9443/jazz/oslc/workflows/
_Wp0-gCeREd-nSqqeCWspMA/states/bugzillaWorkflow/3

to closed

https://LAP-IBM-853.PSAD.de:9443/jazz/oslc/workflows/
_Wp0-gCeREd-nSqqeCWspMA/states/bugzillaWorkflow/5

20 answers



permanent link
Patrick Streule (4.9k21) | answered Mar 11 '10, 6:08 a.m.
JAZZ DEVELOPER
You can do a regular PUT of the resource as you would for changing any
attribute, but include the workflow action as a URL parameter:

....com.ibm.team.workitem.WorkItem/247?_action=com.ibm.team.workitem.defectWorkflow.action.startWorking

Here's an example curl script which changes the work item's state:

COOKIES=./cookies.txt

URL=https://localhost:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/247?_action=com.ibm.team.workitem.defectWorkflow.action.startWorking

curl -D - -k -b $COOKIES -H "If-Match: $1" -H "Content-Type:
application/x-oslc-cm-change-request+xml" -H "Accept:
application/x-oslc-cm-change-request+xml" -X PUT --data-binary @247.xml $URL


--
Regards,
Patrick
Jazz Work Item Team

Comments
Tony Eastwood commented Jul 12 '12, 10:57 a.m.

How do I determine the list of available '_actions' I could set? That is the set of values similar to: 'com.ibm.team.workitem.defectWorkflow.action.startWorking'

Where is this discoverable for a project? The objects pointed at by existing states looking like 'https://...:9443/ccm/oslc/workflows/.../states/bugzillaWorkflow/' only get me named gifs. How do I get the list of java-like names?

Looking at many questions asked about changing workitem state (and lack of answers!) this topic should be included in: https://jazz.net/wiki/bin/view/Main/WorkItemAPIsForOSLCCM20


Christopher Smith commented Jul 21 '12, 4:35 p.m.

I'm having the same "fun" as Tony. I want to advance a workitem status through the REST api. Following your suggestion works for advancing a "Defect" work item from "New" to "In Progress". I can't do anything else.


Jonas Studer commented Aug 12 '16, 7:06 a.m.

Sadly this doesnt help a lot. Since I do not know the "NEXT possible state".
Is there a way to get to the proper/whole workflow logic?


Donald Nong commented Aug 14 '16, 8:06 p.m.

See Buzz Moschetti's answer. Otherwise open a new post titled "how to find out the valid action for a certain state".


permanent link
Buzz Moschetti (6125) | answered Jan 22 '13, 5:15 p.m.
The general solution is as follows:
 
Accept: application/xml   (NOT rdf+xml)
Do NOT set OSLC-Core-Version to 2.0

Call /ccm/oslc/workflows/$projectAreaId/actions/$workflowTypeName
e.g. /ccm/oslc/workflows/_acueADcNEeGeMZwN8UaGqw/actions/com.ibm.team.workitem.taskWorkflow

This will give you an oslc_cm:Collection of all Action items for that workflow typename, e.g.
<rtc_cm:Action rdf:resource="https://rtc.jpmchase.net:9443/ccm/oslc/workflows/_acueADcNEeGeMZwN8UaGqw/actions/com.ibm.team.workitem.taskWorkflow/com.ibm.team.workitem.taskWorkflow.action.a1">
<dc:identifier>com.ibm.team.workitem.taskWorkflow.action.a1</dc:identifier>
<rtc_cm:resultState rdf:resource="https://rtc.jpmchase.net:9443/ccm/oslc/workflows/_acueADcNEeGeMZwN8UaGqw/states/com.ibm.team.workitem.taskWorkflow/2"/>
<dc:title>Reopen</dc:title>
<rtc_cm:iconUrl>https://rtc.jpmchase.net:9443/ccm/service/com.ibm.team.workitem.common.internal.model.IImageContentService/processattachment/_acueADcNEeGeMZwN8UaGqw/workflow/reopen.gif</rtc_cm:iconUrl>
</rtc_cm:Action>

Each Action item has an rdf:resource, e.g.:
https://rtc.jpmchase.net:9443/ccm/oslc/workflows/_acueADcNEeGeMZwN8UaGqw/actions/com.ibm.team.workitem.taskWorkflow/com.ibm.team.workitem.taskWorkflow.action.a1

The "tail" of that resource becomes the argument to the ?_action call, e.g.
    $url .= '?_action=com.ibm.team.workitem.taskWorkflow.action.a1'

Because each Action item also has a dc:title  (Reopen in the example above), you can create a user-friendly mapping.

Note that once you call _action with an action that puts the item in a terminal state (like Invalid), you cannot go back to New.   No surprise here, and it's same behavior as in the GUI.

Other combinations of setting OSLC-Core-Version to 2.0 and setting Accept to application/rdf+xml do not work in that you cannot get to the dc:title to get the friendly name.   If you do NOT need the friendly name, feel free to set
OSLC-Core-Version to 2.0 and use rdf.





Comments
Buzz Moschetti commented Jan 23 '13, 7:59 a.m.

Each Action item ALSO has the "tail" explicitly set in the dc:identifier tag, e.g.
<dc:identifier>com.ibm.team.workitem.taskWorkflow.action.a1</dc:identifier>
That's probably a better way to get at it....


permanent link
Erik Vonderheid (461) | answered Mar 10 '10, 7:09 a.m.
I found this wiki side https://jazz.net/wiki/bin/view/Main/ResourceOrientedWorkItemAPIv2#Attributes. It seems that the state is not modifiable via REST call.

permanent link
Dominic Evans (6653) | answered Mar 11 '10, 6:38 a.m.
On 11/03/10 10:54, Patrick Streule wrote:
You can do a regular PUT of the resource as you would for changing any
attribute, but include the workflow action as a URL parameter:

...com.ibm.team.workitem.WorkItem/247?_action=com.ibm.team.workitem.defectWorkflow.action.startWorking


Patrick, I've been doing similar calls via curl in our build scripts to
automatically resolve defects once they appear in a clean build.

Currently there doesn't appear to be a REST-like way to automatically
add Verification reviews in a similar way.

I had previously noticed work item 40864 http://goo.gl/nzPz which
extended WorkItemClient.js to allow approvals to be created.

Is there currently any way to achieve this via curl ?

Cheers,
Dom

permanent link
Darren Cheng (6151) | answered Mar 12 '10, 8:56 a.m.
Hi Patrick,

Thanks for the above tip. I had a go as I am also looking to change a work item state over HTTP. I pasted the below into my browser for work item with id 220. I just wanted to move the item from a NEW state to the In PROGRESS state.

https://dptlfccm01:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/220?_action=com.ibm.team.workitem.bugzillaWorkflow.action.startWorking

However, it didn't work. The work item loaded and displayed all the field, but the state had not changed and remained in the NEW state.

What am I doing wrong?

Thanks,
Darren

You can do a regular PUT of the resource as you would for changing any
attribute, but include the workflow action as a URL parameter:

....com.ibm.team.workitem.WorkItem/247?_action=com.ibm.team.workitem.defectWorkflow.action.startWorking

Here's an example curl script which changes the work item's state:

COOKIES=./cookies.txt

URL=https://localhost:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/247?_action=com.ibm.team.workitem.defectWorkflow.action.startWorking

curl -D - -k -b $COOKIES -H &quot;If-Match: $1&quot; -H &quot;Content-Type:
application/x-oslc-cm-change-request+xml&quot; -H &quot;Accept:
application/x-oslc-cm-change-request+xml&quot; -X PUT --data-binary @247.xml $URL


--
Regards,
Patrick
Jazz Work Item Team

permanent link
Patrick Streule (4.9k21) | answered Mar 12 '10, 12:23 p.m.
JAZZ DEVELOPER
Thanks for the above tip. I had a go as I am also looking to change a
work item state over HTTP. I pasted the below into my browser for
work item with id 220. I just wanted to move the item from a NEW
state to the In PROGRESS state.

https://dptlfccm01:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/220?_action=com.ibm.team.workitem.bugzillaWorkflow.action.startWorking

However, it didn't work. The work item loaded and displayed all the
field, but the state had not changed and remained in the NEW state.

What am I doing wrong?

When you paste this URL into the browser, it will send a GET request to
the server. A GET must not change a resource, however. You need a PUT or
PATCH request to modify the work item, including its state.

You can try that e.g. using
https://addons.mozilla.org/en-US/firefox/addon/2691


--
Regards,
Patrick
Jazz Work Item Team

permanent link
Darren Cheng (6151) | answered Mar 16 '10, 8:05 a.m.
Hi Patrick,

Thanks for answering my (newbie) question earlier. I've played around a bit more to get an understanding of how it works but still can't seem to get the state to change. Can I ask for your help once again? Here's what I did:

I first got the JSON representation of the work item by running a Windows script:

=====================================================================================
set COOKIES=cookies.txt

set USER=administrator
set PASSWORD=administrator
set HOST=&quot;https://dptlfccm01:9443/jazz&quot;

curl -k -c %COOKIES% &quot;%HOST%/authenticated/identity&quot;

curl -k -L -b %COOKIES% -c %COOKIES% -d j_username=%USER% -d j_password=%PASSWORD% &quot;%HOST%/authenticated/j_security_check&quot;

curl -D - -k -b %COOKIES% -o 220.json -H &quot;Accept: application/x-oslc-cm-changerequest+json&quot; &quot;%HOST%/oslc/workitems/220.json&quot;

=====================================================================================

The ETag returned was _b9dv4DDoEd-YpvOcpbHK1w.

This successfully creates 220.json. The data inside specifies that the state is in state 3 (resolved):

=====================================================================================
&quot;rtc_cm:state&quot;:{&quot;rdf:resource&quot;:&quot;https:\/\/dptlfccm01:9443\/jazz\/oslc\/workflows\/_s1JUcC0TEd-bnbOLrZ2Idw\/states\/bugzillaWorkflow\/3&quot;}
=====================================================================================

I wanted to progress this state to state 5 (closed). So I changed the line in the JSON file to the below and saved it(all other data was left unchanged):

=====================================================================================
&quot;rtc_cm:state&quot;:{&quot;rdf:resource&quot;:&quot;https:\/\/dptlfccm01:9443\/jazz\/oslc\/workflows\/_s1JUcC0TEd-bnbOLrZ2Idw\/states\/bugzillaWorkflow\/5&quot;}
=====================================================================================

Then, I ran a second script with the following URL and Curl command to put the file back into RTC:

=====================================================================================
set COOKIES=cookies.txt

set URL=&quot;https://dptlfccm01:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/220?_action=com.ibm.team.workitem.bugzillaWorkflow.action.close&quot;

curl -D - -k -b %COOKIES% -H &quot;If-Match: _b9dv4DDoEd-YpvOcpbHK1w&quot; -H &quot;Content-Type: application/x-oslc-cm-change-request+json&quot; -H &quot;Accept: application/x-oslc-cm-change-request+json&quot; -X PUT --data-binary @220.json %URL%

=====================================================================================

The script executes successfully with no errors reported in the terminal window but a new ETag is supplied and when I re-run the first script to see the changes, the state is still in state 3. Really strange!

I apologise for the rather long question, but I've been totally stuck for a while now. Your help would be much appreciated! :-)

Many Thanks,
Darren

permanent link
Darren Cheng (6151) | answered Mar 16 '10, 8:12 a.m.
Ah, I forgot to add, if I change the data of another property e.g. dc:title, the property is updated perfectly. It just doesn't work for rtc_cm:state

permanent link
Darren Cheng (6151) | answered Mar 16 '10, 9:41 a.m.
Hi,

I just found the solution to the problem. In the action parameter at the end of the URL, the action should not have contained com.ibm.team.workitem and should just have been bugzillaWorkflow.action.close. This allowed the state to be changed from resolved to closed.

The final URL is:

https://dptlfccm01:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/220?_action=bugzillaWorkflow.action.close

permanent link
Patrick Streule (4.9k21) | answered Mar 17 '10, 4:41 a.m.
JAZZ DEVELOPER
I just found the solution to the problem. In the action parameter at
the end of the URL, the action should not have contained
com.ibm.team.workitem and should just
have been bugzillaWorkflow.action.close.
This allowed the state to be changed from resolved to closed.

The final URL is:

https://dptlfccm01:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/220?_action=bugzillaWorkflow.action.close

Good to hear that you got it to work. Please note that the action IDs
are specific to a workflow, so the action ID for resolving a work item
can vary with the work item type. This may not be an issue in your case,
but should be considered in a general-purpose solution.

--
Regards,
Patrick
Jazz Work Item Team

Your answer


Register or to post your answer.