Unable to Execute a task using the REST API

1
0
-1

I deployed the application as described in the documentation (the ClaimManagement application).

I am able to login, create process, create a new case.

I am completely lost as I can't find detailed enough documentation about it.

But I am unable to execute a task.

I always receive a HTTP error 404 when doing a PUT with the "assumed" correct request.

Hereunder is the Wireshark log of the request:

PUT /bonita/API/bpm/task/20024 HTTP/1.1

Set-Cookie: BOS_Locale=en; Path=/; SameSite=Lax

X-Bonita-API-Token: 033053fb-4fcf-4894-a1e1-308ba8e533db

User-Agent: Jakarta Commons-HttpClient/3.1

Host: 127.0.0.1:8080

Cookie: $Version=0; bonita.tenant=1

Cookie: $Version=0; JSESSIONID=DC812B59C9B580961845D7587730ACDD; $Path=/

Cookie: $Version=0; X-Bonita-API-Token=033053fb-4fcf-4894-a1e1-308ba8e533db; $Path=/

Cookie: $Version=0; BOS_Locale=en; $Path=/

Content-Length: 235

Content-Type: application/json; charset=UTF-8

{

"state": "completed",

"variables": [

{ "name":"claimInput1",

"value":[

{

"name" : "answer", "value" : "Good"

}

]}

]

}HTTP/1.1 404

Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate

Content-Type: application/json;charset=UTF-8

Transfer-Encoding: chunked

Date: Sun, 09 Jan 2022 20:39:17 GMT

3 answers

1
0
-1
This one is the BEST answer!

I think I got what was wrong:

  • you must assign tasks
  • user task must use the userTask endpoint. Using task manualTask won't work

So correct steps are:

  • login: POST /bonita/loginservice

  • list available processes : GET /bonita/API/bpm/process?c=10&p=0

  • Ger process definition : GET /bonita/API/bpm/case?c=10&p=0&f=processDefinitionId%3D5738129050431799262

  • Start process (new case) : POST /bonita/API/bpm/process/5738129050431799262/instantiation

  • Get user task ID : GET /bonita/API/bpm/humanTask?c=10&p=0&f=caseId%3D4002 (4002 comes from previous step answer)

  • Assign task :PUT /bonita/API/bpm/userTask/80007 (80007 comes from previous step answer)

  • Verify : GET /bonita/API/bpm/humanTask?c=10&p=0&f=caseId%3D4002

  • Execute process step : POST /bonita/API/bpm/userTask/80007/execution

  • Check task : GET /bonita/API/bpm/humanTask?c=10&p=0&f=caseId%3D4002

    • Here the task Id changes because you are in "step 2"

Comments

Submitted by weglineduardo on Tue, 10/18/2022 - 17:08

hello bcalleb.
I have a question.
Do you have to assign permissions for the user who logs in with the api in some configuration file to do the POST and PUT ?

When i use
start process (POST /bonita/API/bpm/process/6209981529276529349/instantiation returns an http 401

I'm logging in with walter.bates and it's managed. It never allows me with this user to post, put, delete or path in any case, task, group or any other.
Do you have an example of a configuration file or do you know what to do to solve this?

1
0
-1

Hi,

What you are trying to do is execute a User Task by fulfilling its contract. Based on the documentation: https://documentation.bonitasoft.com/bonita/latest/api/bpm-api#_execute_a_task_with_contract

Here is what you should do:

POST /API/bpm/userTask/:userTaskId/execution ---> In your example the userTaskId is 40002

Request Payload

  • A JSON object matching task contract. Execute a task providing correct contract values.

    {
      "ticket_comment":"This is a comment"   // Please provide here the input names and values expected by your task contract
    }
  • Optional URL Parameter
    assign=true, assign the task to the current user and execute the task.

  • Success Response

    • Code: 204

Let me know if it helps,

Captain Bonita

1
0
-1

Hi,

It seems you are trying to execute the task with id 20024 (as per the URL you mention: /bonita/API/bpm/task/20024); can you make sure the id represents really the tasks you are trying to execute?

The 404 HTTP error code suggests that the task id is not found.

Captain Bonita

Comments

Submitted by bcalleb on Mon, 01/24/2022 - 22:31

I did the test again with the same result and unless I misunderstood something the id I use is correct.

See hereunder for more details:

  1. login (POST /bonita/loginservice HTTP/1.1 --> HTTP Code 204)
  2. fetch processes list (GET /bonita/API/bpm/process?c=10&p=0 HTTP/1.1 --> HTTP Code 200)
    1. Response :[{"displayDescription":"","deploymentDate":"2022-01-24 20:52:55.466","displayName":"ClaimsManagement","name":"ClaimsManagement","description":"","deployedBy":"4","id":"6209981529276529349","activationState":"ENABLED","version":"1.0","configurationState":"RESOLVED","last_update_date":"2022-01-24 20:52:55.628","actorinitiatorid":"403"}
  3. start process (POST /bonita/API/bpm/process/6209981529276529349/instantiation HTTP/1.1 -->HTTP Code 200)
  4. fetch cases (GET /bonita/API/bpm/case?c=10&p=0&f=processDefinitionId%3D6209981529276529349 --> HTTP Code 200. )
  5. start case (POST /bonita/API/bpm/process/6209981529276529349/instantiation --> HTTP Code 200. Case ID : 2001)
  6. Get case information (GET /bonita/API/bpm/task?c=10&p=0&f=caseId%3D2001 HTTP/1.1 --> HTTP Code 200)
    1. Response :[{"displayDescription":"","executedBy":"0","rootContainerId":"2001","assigned_date":"","displayName":"Review and answer claim","executedBySubstitute":"0","dueDate":"","description":"","type":"USER_TASK","priority":"normal","actorId":"403","processId":"6209981529276529349","caseId":"2001","name":"Review and answer claim","reached_state_date":"2022-01-24 20:55:04.807","rootCaseId":"2001","id":"40002","state":"initializing","parentCaseId":"2001","last_update_date":"2022-01-24 20:55:04.806","assigned_id":""}]
  7. do task (PUT /bonita/API/bpm/task/40002 --> HTTP Code 404):
    1. POST DATA:{"state": "completed","variables": [{ "name":"claimInput1",

      "value":[{"name" : "answer", "value" : "Good"}]}]}

Submitted by weglineduardo on Tue, 10/18/2022 - 17:08

hello bcalleb.
I have a question.
Do you have to assign permissions for the user who logs in with the api in some configuration file to do the POST and PUT ?

When i use
start process (POST /bonita/API/bpm/process/6209981529276529349/instantiation returns an http 401

I'm logging in with walter.bates and it's managed. It never allows me with this user to post, put, delete or path in any case, task, group or any other.
Do you have an example of a configuration file or do you know what to do to solve this?

Submitted by weglineduardo on Mon, 12/26/2022 - 21:21

Hello, were you able to find a solution?
My problem is something similar

put url

http://localhost:8080/bonita/API/bpm/humanTask/1280124

I want to make a put to the task and I fulfill the expected contract

{ "state": "completed",

"serviceRequestInput": [ {

"notas": "notas aqui"

} ]}

but it answers me

"message": "USERNAME=walter.bates | org.bonitasoft.engine.bpm.contract.ContractViolationException: Error while validating expected inputs: Expected input [serviceRequestInput] is missing"

Thanks for commenting on a solution.

Notifications