How do you update workitems using Perl LWP UserAgent?
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
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
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');
HTTP 406 basically means that the application does not accept the value of the "Accept" header. Try with "/" or "application/xml" instead.
I've tried both of those along with application/rdf+xml and application/x-oslc-cm-change-request+xml. Everything comes back error 406.
Oh...you are calling the action directly, and you may try "application/json", which is the only accepted format for some internal APIs.
I got the same result as the others with application/json.