cumulocity

Check if an array contains a value Query in Cumulocity REST API


I have a managed object of type “ABC” with a fragment “A”, that has sub-structure as following:

{
    "type": "ABC",
    "A": {
        "value": ["B", "C"]
    }
}

How would one create a filter/query that would check if "A" fragment contains “C” in the "value" array?

That query fails:

{{url}}/inventory/managedObjects?query=$filter=(type+eq+'ABC'+and+A.value+has+‘C‘)

With

{
    "error": "inventory/Invalid Data",
    "message": "Find by filter query failed : Query '$filter=(type eq 'ABC' and A.value has ‘C‘)' could not be understood. Please try again.",
    "info": "https://www.cumulocity.com/guides/reference-guide/#error_reporting"
}

Cumulocity doc about querying REST API.

Solution: Use eq instead of has:

{{url}}/inventory/managedObjects?query=$filter=(type+eq+'ABC'+and+A.value+eq+‘C‘)

Solution

  • I couldn't find a source but the following is working for me with the expected result:

    {{url}}/inventory/managedObjects?query=$filter=(type+eq+'ABC'+and+A.value+eq+'C')
    

    So basically you need to use the eq operator for your use case.