No result for /rest/history/process-definition/{processDefinitionId}/statistics

Hello,

I’m trying to get the process definition statistics using the following endpoint:

/rest/history/process-definition/{processDefinitionId}/statistics

But I’m not getting any results. Is this an enterprise feature API?

Any help would be appreciated

Hello @aminmc,

Historic activity statistics are included in the community edition.
What response code do you get?

Cheers,
Tassilo

Hi @tasso94

Response code is 200. I’ve tried using the process definition id, process definition key and even process instance id (although I’m pretty sure it’s the process definition id).

Thanks

Hi @aminmc,

you will receive an empty JSON array even if the process definition id does not exist.

Are you sure that you used the right process definition id?
You can validate it by listing all deployed process definitions with the following REST API endpoint:

GET /process-definition

Does this answer your question?

Cheers,
Tassilo

Hi @tasso94

Yep I validated the process definition id but still no luck. I’m reluctant to build my own api if this doesn’t work.

Cheers

Hi @aminmc,

what kind of data are you expecting to receive?

If you perform a request without any parameter you will only receive running activity instances.
To include activity instances which have already been finished, please see the query parameters section.

Does this answer your question?

Cheers,
Tassilo

Hi @tasso94

I’m afraid I get no data just an empty array in the body. I’ve used no query parameters and nothing. I would expect to see some results. Even if I programmatically execute the same query as the REST API I still get no results.

Thanks
Amin

Hi @aminmc,

Do you have your history level set to full?

Cheers,
Christian

Hi @hawky4s

Yep. It’s weird. I’m preplexed by the behaviour.

Cheers

Do you get a result when issuing GET /history/activity-instance/count?

Yep getting results using count. I’ll dig around further.

Are you using authentication? If yes, is the authenticated user authorized to access any history data?

@aminmc
I’m facing the same issue, /process-definition/{id}/statistics this rest call returns an empty array but invoking /history/process-instance/aProcInstId gives proper result. What could be the possible reason ?
Were you able to fix this ??

Hi @abhinay_pandey

By default, REST api /process-definition/{id}/statistics returns only running activity instances. This means if activity instance has completed its execution then it won’t be part of the result. Please check the state of Activity Instance for the provided process definition.

Where as REST api /history/process-instance/aProcInstId returns process instances irrespective of their state ( Active, Suspended, Completed, Terminated etc.). That’s the reason this API will always return non-empty result if process instance id exists and is valid.

Does it help?

Best,
Garima

1 Like

You are right. It doesn’t lists completed instances but contains active instances instead.
My requirement is to get the list of Running, Suspended, Finished and Failed instances of a particular Process Definition. Is there any other way to achieve this ?

Hello @abhinay_pandey

REST api https://docs.camunda.org/manual/latest/reference/rest/history/activity-instance/get-activity-instance-query/#method might help you with your use-case.
You can use processDefinitionId as a query parameter in order to retrieve activity instances from historic table for specific process definition id. It will give all the activity instances which got finished, unfinished, completed scope, canceled.

GET /history/activity-instance?processDefinitionId=

Best,
Garima

1 Like