REST API Create (or update) variables on a process instance

When I attempt to run the POST or PUT in postman or run a sample in swagger

PUT runtime/process-instances/{processInstanceId}/variables or

POST runtime/process-instances/{processInstanceId}/variables

            {
                "name": "variableName",
                "type": "string",
                "value": "testvalue",
                "scope": "local"
            }

I receive
{
“message”: “Bad request”,
“exception”: “Failed to serialize to a RestVariable instance”
}

The variables need to be in a json array, so wrap your variable in [ ] and it should be ok.

When I try the following still get same error

If I remove “variables” : then get json syntax error in postman

{
“variables” : [
{
“name”: “testvariabler”,
“type”: “string”,
“value”: “testvalue”,
“scope”: “local”
}
]
}

During my google research someone had same issue but with alfresco
https://community.alfresco.com/thread/231605-failed-to-serialize-to-a-restvariable-instance

and it was mentioned … because RestVariable class does not implement Serializable interface. ??

You don’t need the ‘variables’ in the body, just the array with the variable. See the docs at https://flowable.org/docs/userguide/index.html#_create_or_update_variables_on_a_process_instance

Perfect … that works .

thanks for the help on this. I was assuming like the other rest api calls the json would begin and end with {}

Just in case you try it out, this endpoint [PUT] /runtime/tasks/{taskId}/variables/{variableName} only accepts a single variable so unlike the POST, your body cannot include the array wrapper. Just happened upon it a couple days ago :slight_smile: