Catalog object search not working as documented

This is mostly a bug report so that this issue can be corrected or the documentation updated in a future release. I am able to work around this by doing my own filtering (though probably less efficient and using more Square resources).

The searchCatalogObjects endpoint documentation says this about the exact_query attribute_value contents.

The desired value of the search attribute. Matching of the attribute value is case insensitive and can be partial. For example, if a specified value of “sma”, objects with the named attribute value of “Small”, “small” are both matched. [emphasis added]

In my testing using the sku attribute, partial search values (e.g. “sma” above) DO NOT return results. Using the full contents of the sku attribute (hypothetically “shirt-small-blue”) DOES return the matching item.

In my use case, I am trying to retrieve all ITEM_VARIATION objects that match a specific sku pattern.

Where are you seeing that documented? In our docs the exact_query is documented as:

An exact query expression to return objects with attribute name and value matching the specified attribute name and value exactly. Value matching is case insensitive.

If you use a prefix_query it will return the partial values of the sku. For example:

{
  "object_types": [
    "ITEM", "ITEM_VARIATION"
  ],
  "query": {
    "prefix_query": {
      "attribute_name": "sku",
      "attribute_prefix": "123456789012345678901234567890"
    }
  },
  "limit": 100
}

:slightly_smiling_face:

Hi Bryan,

I mentioned in another topic that I am a big fan of the API Explorer and use it to understand how the calls work before I commit them to my code.

The quoted documentation comes from the API Explorer at https://developer.squareup.com/explorer/square_2023-01-19/catalog-api/search-catalog-objects

I have not tried a prefix_query, but for my particular use case the value I want to match is actually at the tail end of the sku, and I took the “prefix” name literally. Does the attribute_prefix match a partial string not at the beginning of the attribute value?

I just tested, and it looks to me like “prefix” really means “prefix” (as in at the start of the value).

Thanks

Thanks for bringing this to our attention. :slightly_smiling_face:

1 Like