Syntax for history process-instance when variable is a JSON array (REST API)

Hello everyone,
I am having issues with correct syntax for process instance history API via Get Instances (POST).
I have a process variable variableA which is a Json array:
myVariable - [“value1”, “value2”,“value3”].
I need to search process-instance history via REST Api based on one of the values from this this array. ie, I need to find a process instance that had “value1” as part of myVariable array.

What would be a correct format for JSON body:
{
“variables”: [
{
“name”: “myVariable”,
“operator”:???,
“value”: “value1”
}
]
}
Any help is greatly appreciated!

Hello my dear!

Try something along these lines using the processInstanceQuery methods:

POST /history/process-instance
{
   "processInstanceQuery": {
     "variableValueLike": [
       {
         "name": "myVariable",
         "value": "%value1%",
         "type": "json"
       }
     ]
   }
}

If you want you can change the “variableValueLike” for “variableValueEquals” or another of your preference.

(the percent symbol means that you are looking for something that has that value included, for example “%illia%” will find the value “William”.)

A look at the doc will possibly help you with this.

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.2/org/camunda/bpm/engine/runtime/ProcessInstanceQuery.html

Hope I helped you.
If I helped you in any way, leave your like and mark it as “solved” :smiley: hahaha

I don’t see these properties for JSON request body anywhere in the docs
for POST /history/process-instance REST Api:

:frowning_face:

Keep in mind that you are making requests to an API, so you can use the methods in the Java Doc API…

See the link I sent you in the answer above :smiley:

Just below you can check a request I made to my Camunda project using POSTMAN so you can get an idea of how well this works!

Camunda is fantastic my friend… :smiley:
If we know how to use it, we can even make it rain with it hahahaha

See ya :wink:

Regards.
William Robert Alves

1 Like

Thanks for your reply, but that query does not work, and it returns every single process instance from the history. meaning that it ignores all properties of that json request body. :frowning:
Another problem that I noticed by going through the documentation that you sent the link to is that variableValueLike can be used only on String variables.

Yes! “variableValueLike” its only for type String values.

Or, you can trying this way to boolean variables like Camunda docs explain…:

POST /history/process-instance
{
  "variables": [
    {
      "name": "BoolVariable",
      "operator": "eq",
      "value": "true"
    }
  ]
}

Or using it to number values…:

POST /history/process-instance
{
  "variables": [
    {
      "name": "myVariable",
      "operator": "eq",
      "value": "value1"
    }
  ]
}

image

replace the “operator” with any of those that are in the doc and satisfy your condition.

if this doesn’t work… tomorrow I’ll test it more calmly by calling the API through POSTMAN, because today my day was very busy.

Here in Brazil it’s past midnight, and I’m going to sleep now, but in case you can’t solve it, I can try to perform some tests tomorrow and post the results to help you in some way.

See ya :slight_smile:

Regards.
William Robert Alves

Unfortunately, still does not work when myVariable is an array: {“1234”,“5678”]. Works fine for primitive types.

In this example you mentioned, if you make a post with the following payload, does it not work?

{
  "variables": [
    {
      "name": "myVariable",
      "operator": "eq",
      "value": "5678"
    }
  ]
}

It does not. I get empty response.