Set Variables Async endpoint issue

Hi folks, I’m having some trouble using the REST endpoint for Set Variables Async (POST):
https://docs.camunda.org/manual/latest/reference/rest/process-instance/post-set-variables-async/

I’m trying to change the value of a variable of a specific process instance that has been completed, so I’m using the historicProcessInstanceQuery property to look for it.

Here’s what my request looks like:

{
    "historicProcessInstanceQuery": {
        "processInstanceId": "1234567890",
        "processDefinitionKey": "my-proc-definition-key",
        "variables": [
            {
                "name": "MY_VARIABLE_NAME",
                "operator": "eq",
                "value": "oldValue"
            }
        ]
    },
    "variables": {
        "MY_VARIABLE_NAME": {
            "value": "newValue",
            "type": "String"
        }
    }
}

But this is the response I’m getting:
400 Bad Request

{
    "type": "BadUserRequestException",
    "message": "processInstanceIds is empty"
}

I thought that if I specified the historicProcessInstanceQuery, then processInstanceIds would not be required. Is that wrong? Am I missing something?

Thanks,
Kevin

Hi @kevindang88 ,

the parameter processInstanceIds is not required. Either a processInstanceQuery or a historicProcessInstanceQuery is sufficient. The response rather tells you that your query did not deliver any results.
What happens if use your query against the query endpoint. Are any process instances returned?

Kind regards
Adagatiya

Hi @kevindang88 ,
I reproduced your issue and come to the same conclusions.
I always get your “processInstanceIds is empty” message when the process instance is completed.

The message shows up also if I provide the processInstanceIds like

“processInstanceIds”: [“96a68e7c-43b6-11ed-aa36-acde48001122”]

I then tried to apply the same rest call to a running process instance, and it works.

So now I have a doubt. Is this the good api to update variables of completed process instances?
If not, is there an api to update variables of process instances that are completed?

Cheers

Hi @kevindang88 ,

I did some more research and for variable updates every query is strictly reduced to running processes. Also I did not found an api method for modifying finished processes.
So if you really need the change, your best chance is to execute the above mentioned change via SQL. Keep in mind to create a backup + you always need to apply the change to both historic variable tables “ACT_HI_VARINST” and “ACT_HI_DETAIL”. If you want to include non-finished proceses also “ACT_RU_VARIABLES” would need to be modified.

Kind regards
Adagatiya

Hi @Enrico, @Adagatiya,

Thank you both for looking into this!

I was also not able to find a different api for updating variables of process instances that are completed.

Yes, this is what I did to test my query beforehand. When I use that query endpoint, it actually returns exactly the process instance I’m looking for, but when I paste that same query into the Set Variables request body, I get the 400 Bad Request response.

If the Set Variables api only works for processes that are currently running, does it seem redundant to allow both the processInstanceQuery and historicProcessInstanceQuery properties?

Thanks,
Kevin

History is by definition read-only - thus if the process is completed, you cannot set the variables in it.

I’m not sure what the reason for the historicProcessInstanceQuery property would be, but it might be to be able to query the history of a variable for a process that’s currently still active.

1 Like