It's all about the answers!

Ask a question

How do you update workitems using Perl LWP UserAgent?


Shawn Carroll (36213) | asked Apr 10 '18, 10:42 a.m.
edited Apr 10 '18, 10:44 a.m.

I've been trying to post a new workitem to my RTC server then try to use a PUT to update the state of the workitem. So far, I only get a 406 not acceptable error. Here's a section of the code I'm running:

my $url = 'https://serveraddress:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/' . $workItemID;

my @hdrs = (
            'Accept' => 'application/xml',
            'OSLC-Core-Version' => '2.0',
            'Content_Type' => 'application/xml');

my $response = $userAgent->get($url, @hdrs);

my $str = $response->as_string;
my $find = "request.workflow.state.oldState";
my $replace = "request.workflow.state.newState";
$find = quotemeta $find;

$str =~ s/$find/$replace/g;

my @etag = split("ETag:", $str);
@etag = split("\"", $etag[1]);
my $etag_value = $etag[1];

my @strArray = split("encoding=", $str);
$str = "<?xml version=\"1.0\" encoding=" . $strArray[1];
@hdrs = (
            'Accept' => '/',
            'Content_Type' => 'application/rdf+xml',
            'if-match' => $etag_value,
            'Content' => $str);
my $url = new URI::URL('https://serveraddress:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/' . $workItemID);
my $request = HTTP::Request->new("PUT", $url);
my $response = $userAgent->request($request, @hdrs);

One answer



permanent link
Donald Nong (14.5k414) | answered Apr 11 '18, 2:48 a.m.

You cannot modify the state of work item directly using OSLC (via PUT). You have to invoke an "action" to change the state, just like you do on the Web UI. Some discussions in the past may help you a bit.
https://jazz.net/forum/questions/32674/change-workitem-state-via-rest
https://jazz.net/forum/questions/152920/how-find-available-actions-to-change-states-in-rtc-with-oslc


Comments
Shawn Carroll commented Apr 11 '18, 10:36 a.m. | edited Apr 11 '18, 10:47 a.m.

I made these changes to my code to use the action but it still gave me a 406 not acceptable error response:

@hdrs = (
            'Accept' => ' / ',
            'Content_Type' => 'application/rdf+xml',
            'if-match' => $etag_value);

my $url = new URI::URL('https://serveraddress:9443/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/' . $workItemID . '?_action=request.workflow.action.a15');


Donald Nong commented Apr 11 '18, 9:37 p.m.

HTTP 406 basically means that the application does not accept the value of the "Accept" header. Try with "/" or "application/xml" instead.


Shawn Carroll commented Apr 12 '18, 10:29 a.m.

I've tried both of those along with application/rdf+xml and application/x-oslc-cm-change-request+xml. Everything comes back error 406.


Donald Nong commented Apr 13 '18, 6:16 a.m.

Oh...you are calling the action directly, and you may try "application/json", which is the only accepted format for some internal APIs.


Shawn Carroll commented Apr 13 '18, 9:51 a.m.

I got the same result as the others with application/json.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.