Querying commercetools custom fields

Viewed 542

I'm trying to query custom fields using commerce tools. given an object as below

{
  [...]
  "custom": {
    "type": {
      "key": "my-category"
    },
    "fields": {
      "returns": [
                    {obj:  {readStatus: "random"},
                    {travelDestination:"randomTravelDestination"}

                 ],
      "description": "example description"
    }
  }
}

I can easily get for example, the description value with a simple query:

custom(fields(description="example description"))

docs: https://docs.commercetools.com/api/projects/custom-fields.

However, how would I write a query to obtain the value for readStatus. I'm specifically trying to see how to query the content inside an array with multiple values?

1 Answers

As your example is a bit confusing do you have any other examples of the full object that you want to query? If a custom field definition of a custom type on order would look like this:

{
      "name": "shippingAddressPerLineItem",
      "label": {
        "en": "shippingAddressPerLineItem"
      },
      "required": false,
      "type": {
        "name": "Set",
        "elementType": {
          "name": "String"
        }
      },
      "inputHint": "SingleLine"
    }    

And the order would look like this (some fields have been removed here):

{
  "type": "Order",
  "id": "a67e28b0-15fb-40a9-bd44-1c70dbeb7dd1",
  "version": 5,
  "custom": {
    "type": {
      "typeId": "type",
      "id": "e4a75e6f"
    },
    "fields": {
      "shippingAddressPerLineItemV2": [
        "item2",
        "item1",
        "address2",
        "Address1"
      ]
    }
  }
}

The query predicate on orders to find the order with the value "item2" in the set would look like this:

custom(fields(shippingAddressPerLineItem = "item2"))

Related