Tasklist search API not returning process variables

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 ?

@Mohamed_Ahmed_Mohame - I wonder if this related to the scoping of the variables somehow. What results do you get if you use this endpoint?

Hello @nathan.loding ,

This is the result of the Search task variables before and after completing the task

Request:

curl --location 'http://localhost:8082/v1/tasks/2251799814279107/variables/search' \
--header 'Content-Type: application/json' \
--data '{
    "includeVariables": [
        {
            "name": "requestId"
        },
        {
            "name": "userId"
        },
        {
            "name": "employeeAction"
        },
        {
            "name": "action"
        }
    ]
}'

Response before completing the task:

[
    {
        "id": "2251799814279107-requestId",
        "name": "requestId",
        "value": "\"123456\"",
        "isValueTruncated": false,
        "previewValue": "\"123456\"",
        "draft": null
    }
]

Response after completing the task:

[
    {
        "id": "2251799814279107-action",
        "name": "action",
        "value": "\"APPROVE\"",
        "isValueTruncated": false,
        "previewValue": "\"APPROVE\"",
        "draft": null
    },
    {
        "id": "2251799814279107-userId",
        "name": "userId",
        "value": "\"demo\"",
        "isValueTruncated": false,
        "previewValue": "\"demo\"",
        "draft": null
    }
]

It’s the same as the default search task returns but this behaviour only appeared when using the task type as Camunda User Task and not appeared when I choose the job worker user task

So, is there difference in the implementation between the 2 types about saving the variables?

@Mohamed_Ahmed_Mohame , Here when you are using mix of Tasklist API v1 and the new unified API v2.

When you use the Tasklist REST API v1 to search for tasks and include variables via the includeVariables parameter, the response will only include the variables that are currently available and visible in the scope of the task at the time of the query. If you complete a task using the Camunda 8 REST API v2 and pass new variables (like action and userId), these variables are set or updated in the process instance context.

The Tasklist API v1’s /v1/tasks/search endpoint only returns variables that are currently available in the context of the task. Once a task is completed, its context may change, and variables that were local to the task or mapped specifically for that task may no longer be available in the same way.

This seems limitation and behavior in Camunda 8, especially when using a mix of Tasklist API v1 and the new unified API v2.

With the release of Camunda 8.8, there are notable changes regarding the APIs. v1 are deprected in this version and avaialble new APIs with v2. Search user tasks | Camunda 8 Docs

I would suggest to raise a feature request to Camunda if the current APIs do not meet your needs or if you encounter limitations (such as missing variable scoping, lack of includeVariables in v2, or other gaps).

Thanks,

Jignesh

1 Like