Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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);

0 votes



One answer

Permanent link

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

0 votes

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.

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936
× 102
× 17
× 10

Question asked: Apr 10 '18, 10:42 a.m.

Question was seen: 3,100 times

Last updated: Apr 13 '18, 9:51 a.m.

Confirmation Cancel Confirm