2

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
myrdstom
  • 156
  • 3
  • 15

1 Answers1

1

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"))

Jenny
  • 76
  • 1
  • I've created a gist here: https://gist.github.com/myrdstom/a65031e18e329ff89be8f2d18981e3c1 with the actual (trimmed) order. I would be looking for the query predicate to either find the `status` or the `rmaOutcome` – myrdstom Mar 03 '21 at 18:18
  • To add color to this when using the order in the above gist, the following query predicates are successful `'custom(fields(returns(id is defined)))'` `'custom(fields(returns(id = "0a00ac52-1db1-4c5d-b8bb-049c9f6c81df")))'` but this is not `'custom(fields(returns(obj is defined)))'`. which makes me wonder why – myrdstom Mar 04 '21 at 08:54
  • 1
    as far as I can see you are doing an expansion of a set of custom objects while querying the order resource. Only fields that are part of the order resource itself can be queried. You could extend the return status to the order object itself to query for the status on orders – Jenny Mar 05 '21 at 11:29
  • Thank's a lot for taking the time jenny. I understand what I have to do – myrdstom Mar 05 '21 at 13:41