Home > Net >  Camunda Rest - fetch variables of a completed process instance
Camunda Rest - fetch variables of a completed process instance

Time:02-10

I am trying to build an audit trail and print information of the users path to the task completion some data are written in variables.

There are some history endpoints from camunda Rest that can provide every “node” which the task went through.

But there are some extra information in process instance variables that I need but when I try to fetch variables from a process instance that is already completed the API answers with “no process instance with id:xxxx found”

Is there a way to read information in the variables of a completed task so ?

Thank you in advance

CodePudding user response:

When a process instance is completed, its data is removed from the runtime tables, which are accessed by the endpoint you are using for the running instance. All information regarding completed process instances needs to be fetched using the history endpoint (the underlying API accesses the history tables). https://docs.camunda.org/manual/7.16/reference/rest/history/

This endpoint using the query parameter processInstanceId will return the data of a completed instance: https://docs.camunda.org/manual/7.16/reference/rest/history/variable-instance/get-variable-instance-query/

Example request:

curl -X GET "http://localhost:8080/engine-rest/history/variable-instance?processInstanceId=5487fe88-72d2-11ec-b607-0242ac110002" -H  "accept: application/json"

Example response:

[
  {
    "type": "String",
    "value": "GPFE-23232323",
    "valueInfo": {},
    "id": "54890ff9-72d2-11ec-b607-0242ac110002",
    "name": "invoiceNumber",
    "processDefinitionKey": "invoice",
    "processDefinitionId": "invoice:1:53c23d7a-72d2-11ec-b607-0242ac110002",
    "processInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "executionId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "activityInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "caseDefinitionKey": null,
    "caseDefinitionId": null,
    "caseInstanceId": null,
    "caseExecutionId": null,
    "taskId": null,
    "errorMessage": null,
    "tenantId": null,
    "state": "CREATED",
    "createTime": "2022-01-11T11:33:42.862 0000",
    "removalTime": null,
    "rootProcessInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002"
  },
  {
    "type": "String",
    "value": "Travel Expenses",
    "valueInfo": {},
    "id": "5489ac44-72d2-11ec-b607-0242ac110002",
    "name": "invoiceCategory",
    "processDefinitionKey": "invoice",
    "processDefinitionId": "invoice:1:53c23d7a-72d2-11ec-b607-0242ac110002",
    "processInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "executionId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "activityInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "caseDefinitionKey": null,
    "caseDefinitionId": null,
    "caseInstanceId": null,
    "caseExecutionId": null,
    "taskId": null,
    "errorMessage": null,
    "tenantId": null,
    "state": "CREATED",
    "createTime": "2022-01-11T11:33:42.865 0000",
    "removalTime": null,
    "rootProcessInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002"
  },
  {
    "type": "Object",
    "value": [
      "accounting",
      "sales"
    ],
    "valueInfo": {
      "objectTypeName": "java.util.ArrayList",
      "serializationDataFormat": "application/x-java-serialized-object"
    },
    "id": "54a6aa32-72d2-11ec-b607-0242ac110002",
    "name": "approverGroups",
    "processDefinitionKey": "invoice",
    "processDefinitionId": "invoice:1:53c23d7a-72d2-11ec-b607-0242ac110002",
    "processInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "executionId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "activityInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002",
    "caseDefinitionKey": null,
    "caseDefinitionId": null,
    "caseInstanceId": null,
    "caseExecutionId": null,
    "taskId": null,
    "errorMessage": null,
    "tenantId": null,
    "state": "CREATED",
    "createTime": "2022-01-11T11:33:43.055 0000",
    "removalTime": null,
    "rootProcessInstanceId": "5487fe88-72d2-11ec-b607-0242ac110002"
  }
]
  • Related