How can I get the process definition tasks through API

My use case is a purchase order request which needs to go through several approvals. For the request creator, I would like to show the status of the request visually as a sequence (like a timeline) of approval tasks with each task having the status approved/disapproved.

Using the /task endpoint I am able to get the current task for a process instance, and using the /history/task endpoint I get all completed tasks plus current task.

Is there any way to get the list of all tasks in a process definition/process instance?

This question is similar https://forum.camunda.io/t/camunda-api-to-get-list-of-tasks-in-a-process-definition/22026/4

P.S. I had asked the same question on twitter, but was redirected to ask here.

Hi @johnjacobkenny

Are you looking for a list of all tasks that have been completed on a process instance?
Or are you looking for all of the tasks in a given model?

Hi @Niall

I am able to get the list of completed tasks for the process instance using /history/task endpoint (correct me if I’m wrong here :slightly_smiling_face:). I would need this data to show the status of previously completed tasks for the process instance.

However, I also want to show the user the list of all future/pending tasks for that process instance - for which I can use the tasks from the process definition (the BPMN model).

Please let me know if my thought process is not the right way to go about it.

This history aspect is correct - the future is more complicated.
For a completely liner model this would be quite easy - you’d just need to get the model and query it for the user tasks that have no yet showed up in the history call for the given instance. When a model is even a little more complex just with some XOR gateways it becomes harder to predict and then even more complicated when you take into account parallel task and event based sub processes.

For that reason it might be a good idea to think about exactly what you need the user to know - if it’s a status you’re looking for you could consider a series of milestones that update a status variable. If it’s more concrete phases then perhaps a the instance could store a list containing the phases yet to be completed.

You could always just query the process model itself and try to workout what the “next steps” might be but i’ve found this ends up being very complex.

1 Like

@Niall That makes sense, and I’ll take that direction. Thanks for helping out :slightly_smiling_face:

@Niall is using a none intermediate event the right way to model a milestone? And is this how to update the status variable?

image

Or is it a better option to do like this,

Where I am adding a create listener and then modifying the status variable.

It really depends on what you’re trying to achieve. Either of the options should work.

1 Like