Hi there, I’ve created a catalog custom attribute and applied it to all items. However, when creating a new item via the dashboard, the custom attribute is not populated. This is breaking some functionality in my implementation.
I am using “Search catalog items” API custom_attribute_filters
> Boolean filter. I rely on the custom attribute to be False
for my particular use case to work properly. However when a new catalog item is added via the dashboard, the custom attribute is not even present on the catalog item. In order for the value to be set to False
, I need to edit the item, manully toggle the custom attribute and save it. The first toggle action adds the custom attribute to the catalog item, and sets it to True
. The 2nd toggle, then sets it to False
.
It would be wonderful if there was an option to set a default value for the custom attribute when new items are added via the dashboard, ie: by a merchant or staff. Currently, we are having to handle this scenario with the manual steps outlined above.
I could not find a way around this using the API. There doesn’t seem to be a way to structure the “Search catalog items” custom_attribute_filters to filter based on the absence of a custom attribute.
Thanks, Cam
Hey @camslice! Thanks for your feedback, I’ll be sure to mark it down as a feature request.
You’re correct, there is not currently a way to use SearchCatalogItems to filter specifically for the absence of a custom attribute. If possible, you may find it easier to invert the logic of your custom attribute and check for True
instead — that way you can check for items that explicitly had that set to True.
1 Like
Hi Josh, thanks for getting back to me.
To be clear, the feature I’m requesting is the ability to set a default value for catalog item custom attribute. Can you confirm that my findings are correct? That is; when a catalog item is created via the dashboard, it has no custom attributes set. Also, that in order for a custom attribute to be set on an item, the item needs to be edited and the custom attribute modified. Is that correct?
Thanks, Cam
Hi Cam,
Yes, your findings are correct. On creation, items will not have custom attributes set. Once the attribute has been modified (either enabling or disabling it), the field will be populated. That’s the feature request I’ve noted down, sorry for the ambiguity in my message!
1 Like
Ok thanks Josh. I guess the only automated solution at this stage is a cron job that periodically cycles through the catalog and sets the custom attribute to False
for any items where it is not defined. Are there rate limits on the Catalog API that might affect this?
No problem!
There are rate limits for Catalog API, but Square does not currently publicize what those limits are. Instead, we encourage developers to handle the rate limits gracefully be building in a retry mechanism with exponential retry attempts. When your application receives a 429 rate limit error from a request, you should attempt to retry at exponentially increasing intervals.
1 Like
Interesting. Or would a webhook be a better solution? Basically trigger a task to update the custom attribute whenever a new catalog item is added. Do you think that would work?
Hi Josh, do you think a better solution for this would be to use a webhook? I need a way to automatically set a default for a custom attribute when a catalog item is added via the dashboard. Thanks
Is there a reason your not just looking for the custom attribute to be true
? Then if false
or not present on the item you know that it’s false
by default?
Thanks for the suggestion Bryan, but it doesn’t fit my use case. I’ll explain it in more detail and maybe you can offer an alternative solution.
I have implemented a custom wholesale login for our store. Once logged in, a wholesale customer has access to the entire catalog. That means, they can see both “Retail” items and “Wholesale” items. I am distinguishing the difference here using a custom attribute, ie: “wholesale: true/false”
For users who are not logged in, I need to make sure that wholesale items are filtered out. The current solution is a filter that matches the condition “wholesale === false”. This is where I face a problem, because new items added via the dashboard don’t have the custom attribute set.
Categories don’t seem like a sensible approach either, because it would still require an extra step by staff adding the items to make sure they are added to a “Retail” category.
Can you think of a better way?
Thanks
Okay, great! You know if you instead filter wholesale on wholesale == true
then you’ll be sure to catch 100% of the wholesale new items. Basically look for wholesale == true
and if true
only show to customers with the wholesale login.
Thanks for your response Bryan, but you’re still missing the point. How can I filter out the wholesale items so that retail customers who are not logged in won’t see them?
There is currently no way to negate the condition.
If wholesale is true only show to logged in customer. Else don’t show wholesale == true
items. That way you gate all the wholesale items to just logged in customers and everyone else will see the regular items.
So you what you saying is I need to filter out wholesale items on the client. I have to pull the entire catalaog first, then use code to filter out wholesale items for retail customers. There is no way to achieve this directly via the API correct?
You can do the filter on the client or on your server before you send it to the client.
This breaks cursor behaviour. If I filter out items on the client/server, then try to get the next set of items from the API the number of items returned will likely also require further filtering.
Ideally the API can do the filtering and the limit
I set for each request returns the number of items I expect. Then I can display them in a predictable fashion on the client. All this client/server side filtering means the number of items displayed on the client for each API call using a cursor will not be the same. Pretty clumsy.
Is there a reason you can’t table the data on your server and only call the API when updates are needed? That way you can appropriately filter to your customers.
Just more overhead. More code and database to maintain. Calling the API directly is more lightweight solution with less points of failure.
If I was to hypothetically implement this, how would I know when updates are needed? Would a webhook serve this purpose?
If I need to run a cron, I may as well just make the cron update all the custom attributes…
A webhook is triggered when catalog objects are updated. You can use the returned timestamp in the webhook payload to get all the updated/created items with a SearchCatalog
call. Here’s the link to the documentation.
Ok thanks Bryan, I’ll probably just use the webhook to update the custom attribute until my feature request is implemented