Hello All,
I am using self-managed Camunda version 8.7.1 and I am trying to call the search tasks API with the option include variables to retrieve the tasks and process variables
It’s working correct when the task state is CREATED but when the task state is converted to CANCELED or COMPLETED the only variables returned are the variables passed in the complete task API only
for example, In this test process ( test.bpmn (2.7 KB) )
I added process variable “requestId” with value “123456”
and in the user task with type “Camunda user task“ I am waiting 2 variable “userId” which I mapped it to the same name and “action” which I mapped it to “employeeAction”.
and these are the requests I sent with the response
first, The search tasks when the task state CREATED
Request:
curl --location 'http://localhost:8082/v1/tasks/search' \
--header 'Content-Type: application/json' \
--data '{
"processInstanceKey": "2251799814193378",
"includeVariables": [
{
"name": "requestId"
},
{
"name": "userId"
},
{
"name": "employeeAction"
}
]
}
'
Response:
[
{
"id": "2251799814193384",
"name": "User task",
"taskDefinitionId": "Activity_0qktzzy",
"processName": "Testing process",
"creationDate": "2025-10-26T11:19:38.965+0000",
"completionDate": null,
"assignee": null,
"taskState": "CREATED",
"sortValues": [
"1761477578965",
"2251799814193384"
],
"isFirst": true,
"formKey": null,
"formId": null,
"formVersion": null,
"isFormEmbedded": null,
"processDefinitionKey": "2251799814193186",
"processInstanceKey": "2251799814193378",
"tenantId": "<default>",
"dueDate": null,
"followUpDate": null,
"candidateGroups": null,
"candidateUsers": null,
"variables": [
{
"id": "2251799814193378-requestId",
"name": "requestId",
"value": "\"123456\"",
"isValueTruncated": false,
"previewValue": "\"123456\""
}
],
"context": null,
"implementation": "ZEEBE_USER_TASK",
"priority": 50
}
]
Second, The complete task API
Request:
curl --location 'http://localhost:8088/v2/user-tasks/2251799814193384/completion' \
--header 'Content-Type: application/json' \
--data '{
"variables": {
"action": "APPROVE",
"userId": "demo"
}
}'
Response: 204
Third, The serach task API but when the task state is COMPLETED
Request:
curl --location 'http://localhost:8082/v1/tasks/search' \
--header 'Content-Type: application/json' \
--data '{
"processInstanceKey": "2251799814193378",
"includeVariables": [
{
"name": "requestId"
},
{
"name": "userId"
},
{
"name": "employeeAction"
},
{
"name": "action"
}
]
}
'
Response:
[
{
"id": "2251799814193384",
"name": "User task",
"taskDefinitionId": "Activity_0qktzzy",
"processName": "Testing process",
"creationDate": "2025-10-26T11:19:38.965+0000",
"completionDate": "2025-10-26T11:24:11.157+0000",
"assignee": null,
"taskState": "COMPLETED",
"sortValues": [
"1761477578965",
"2251799814193384"
],
"isFirst": true,
"formKey": null,
"formId": null,
"formVersion": null,
"isFormEmbedded": null,
"processDefinitionKey": "2251799814193186",
"processInstanceKey": "2251799814193378",
"tenantId": "<default>",
"dueDate": null,
"followUpDate": null,
"candidateGroups": null,
"candidateUsers": null,
"variables": [
{
"id": "2251799814193384-action",
"name": "action",
"value": "\"APPROVE\"",
"isValueTruncated": false,
"previewValue": "\"APPROVE\""
},
{
"id": "2251799814193384-userId",
"name": "userId",
"value": "\"demo\"",
"isValueTruncated": false,
"previewValue": "\"demo\""
}
],
"context": null,
"implementation": "ZEEBE_USER_TASK",
"priority": 50
}
]
So how to show the process variables in the response when the task state is COMPLETED or CANCELED ?