postmancommercetools

How to query the custom fields using the params in postman


"custom": { "type": { "typeId": "type", "id": "023c76a9-25ce-4937-987c-b1375be9f2bf" }, "fields": { "pending": "pending" } }

we have tried passing the query custom(fields(pending= "pending")) Can you please help me to solve this


Solution

  • When trying to query the custom field on an order for example, the query could look something like this: https://api.europe-west1.gcp.commercetools.com/yourProjectKey/orders?where=custom(fields(orderno%20%3D%20%22AA00004557%22))

    query predicate: custom(fields(orderno = "AA00004557"))

    order example:

        {
          "type": "Order",
          "id": "af8381bb-d598-4fff-bfe6-33d7c6eab038",
          "version": 1,
          "country": "DE",
          "orderState": "Open",
          "syncInfo": [],
          "lineItems": [
          ],
          "custom": {
            "type": {
              "typeId": "type",
              "id": "e178b5b4-dede-42bd-9102-fcd5b992a9cf"
            },
            "fields": {
              "orderno": "AA00004557"
            }
          }
        }
    

    If the custom field is from different type than text, enum, date, ltext, lenum you may need a different predicate. Same goes if the custom field is nested within the object, like on a product price.

    You can try to query in impEx first, which makes the decoding and encoding a bit easier. https://impex.europe-west1.gcp.commercetools.com/playground?endpoint=orders&method=read&query-where=custom(fields(orderno+%3D+%22AA00004557%22))&query-sort-order=asc

    You can also have a look at the commercetools documentation for query predicates: https://docs.commercetools.com/api/predicates/query