Get a list of different task types via the REST interface

Hi,

I need to be able to show a list of all outstanding user tasks of different types using the REST interface. One way to do this would be to fetch all tasks via the tasks endpoint and then group the tasks, but that could mean fetching thousands of records without needing most of the information.

Is it possible to just fetch the list of user task types available?

Best regards,
Steinar

What do you mean by “task types”?

I mean different task definitions keys. Sorry for not being clear enough.

Let’s say I have a process called Purchase and it contains only one manual task called AddToBasket. If I start that process, the /task endpoint would give me a reply similar to:

{
    "id": "0024e29b-d5ee-11e8-a538-0a0027000002",
    "name": "Add to basket",
    [... skipping a few properties ...]
    "taskDefinitionKey": "AddToBasket"
}

Now, in my use case, I want to query for the count of all such outstanding taskDefinitionKeys, given a particular process definition id.

Does someone know if such an endpoint exists and if not, would a pull request be likely to be excepted for it?

Yes. Get Task Count (POST) api available to get task count. Refer this:

https://docs.camunda.org/manual/7.9/reference/rest/task/post-query-count/

You can use the usual GET /task or /task/count rest call adding a few parameters:
processDefinitionKey=zzz
taskDefinitionKey==zzz

You can see more deatils in the docs: https://docs.camunda.org/manual/7.10/reference/rest/task/get-query-count/

Thanks for the replies!

I believe that those methods require me to know the taskDefinitionKey before hand. So for my use case I would also require an endpoint that gives me all taskDefinitionKeys available. Does such an endpoint exist (without having to parse the bpmn definitions)?

To clarify: In the example above I have the taskDefinitionKey AddToBasket. In my client code I want to be able to show the count of outstanding tasks without knowing any of the taskDefinitionKeys that are available in the system.

An example would be if I could get this response from GET /task/count?processDefinitionKey=Purchase:

{
  "tasks": [
      { "name": "AddToBasket", "count": 1 }
  ]
}

Rather than just getting the total count as it’s now.

You mean
Count of tasks group by taskDefinitionKey.

That is unavailable through Rest API. I believe that it is impossible to cover all requested queries in the Rest APIs either because those queries considered uncommon or they may affect the performance badly.

But for the being time you still can implement your custom rest service to get it
https://docs.camunda.org/manual/latest/user-guide/process-engine/database/

Thanks for the reply @hassang.

I looked a little bit further into what the Cockpit does (by inspecting the REST calls) and it seems to achieve this goal by calling the statistics endpoint per process:

http://localhost:8080/camunda/api/engine/engine/default/process-definition/{UUID}/statistics

This endpoint returns almost what I’m after, the count per task id (I was hoping for getting the name too, but I might be able to work with this).

I might have to look into using the database like you suggest.

1 Like