cancel
Showing results for 
Search instead for 
Did you mean: 

Problem - invoke claim use rest api?

cuizhiyong
Champ in-the-making
Champ in-the-making
We can invoke the claim request by http://localhost:8080/activiti-rest/service/task/307/claim. But I can't set the userId who the task I want to assignee  like taskService.claim(task.getId(), "fozzie");.
8 REPLIES 8

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
claiming is always done for the current user. I think you need 'assigning'

cuizhiyong
Champ in-the-making
Champ in-the-making
Could you  tell me in more detail.I am a new user.
thank you!

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
sorry, no, I never used the rest api and have unfortunately no time to look into this in detail. The concept of 'claim' vs 'assign' however is independent of the rest api. See the docs for this

ruben1
Champ in-the-making
Champ in-the-making
You do claiming like this:


PUT /task/4711/claim
Host: 127.0.0.1:8080
Accept-Encoding: identity
Content-Length: 26
content-type: application/json
Authorization: Basic cnViZW46cnViZW5zc2VjcmV0cGFzcw==

The Authorization header contains my username and password base64 encoded, '4711' is the tasks id. The user authenticating himself like this is the one claiming the task.

Also note the thread "REST API Bugs/Changes 'kermit' hardcoded" because claiming will always result in 'kermit' getting the task in Activiti 5.7 REST API.

Greets,
Ruben

cuizhiyong
Champ in-the-making
Champ in-the-making
Thank you!

ct1
Champ in-the-making
Champ in-the-making
May we assume that since the fix for the "always claimed by kermit" bug was corrected in the trunk, that the fix made its way into Activiti 5.8?

I am attempting to use the REST interface to claim a task with the following call:


[size=85]

function claimTheTask(theTaskId)
{
    alert("claimTheTask() was called with theTaskId = " + theTaskId);
    var activitiClaimTaskUrl = "http://172.30.1.67:8080/activiti-rest/service/task";
    var theParameters = "/" + theTaskId + "/claim";
    var theRequest = new Ajax.Request
(activitiClaimTaskUrl + theParameters,
{
     requestHeaders: ["ContentType", "application/json;charset=UTF-8"],
     requestHeaders: ["Authorization", "Basic a2VybWl0Omtlcm1pdA=="],
     method: "PUT",
     onFailure:  function (originalRequest)
  {
      document.getElementById("theReply").innerHTML
                  = "Failed with:  Status = " + originalRequest.status;
      alert("onFailure() was called.");
  },
     onSuccess:  function(originalRequest)
  {
      document.getElementById("theReply").innerHTML
      = "Received:  " + originalRequest.responseText;
    alert("onSuccess() was called.");                   }
});
}[/size]

This give me a Status of 405 Method not allowed and the Request Header shows that a "POST" method was issued, instead of a "PUT".  "PUT" is the allowed method.  Could something be replacing the "PUT" my code issues with a "POST"?

Here is the Request Header:

POST http://172.30.1.67:8080/activiti-rest/service/task/953/claim HTTP/1.1
Host: 172.30.1.67:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.23) Gecko/20110920 Firefox/3.6.23
Accept: text/javascript, text/html, application/xml, text/xml, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
X-Requested-With: XMLHttpRequest
X-Prototype-Version: 1.7
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Authorization: Basic a2VybWl0Omtlcm1pdA==
Referer: http://172.30.1.67:8080/Act-Control-Proj2/ActControlServlet
Content-Length: 11
Pragma: no-cache
Cache-Control: no-cache

_method=put

Please point out what I am doing incorrectly.

Thank you.

trademak
Star Contributor
Star Contributor
Hi,

Maybe I don't understand your question, but to use the task operation REST service you are required to use a PUT message.

Best regards,

ct1
Champ in-the-making
Champ in-the-making
Futher investigation revealed the solution.  I was using the prototype.js JavaScript library.  Documention I discovered after posting this question indicated that prototype.js wraps the "PUT" method call inside a "POST" rather than submitting a "PUT".  That explains why the "POST" was indicated in the request header.  When I changed this code to use the XMLHTTPRequest object itself, I was able to submit the "PUT".  I think this question has been resolved.