How to include the Collections field data from Store/Products DB in json file using HTTP Function API?

Hi there :raised_hand_with_fingers_splayed:

The " Collections " field in the Stores/Products collection is a multi-reference field, and multi-reference fields cannot be read with the regular query, you need to use queryReferenced( ) to get the collections of that product.

To do that, you first need to get all the stores’ products, then loop through the items array, query the “Collections” field of each product, and create a new property of the collections on the product item object.

In theory, this should work, but in reality, you’ll get one of these two errors, either " maximum call stack size exceeded " or " request timed out ".

To overcome this issue, I suggest making a cron job on the backed that will do the above but with a limited amount of products (20), then store the already patched products in a separate database, the collections must be stored as regular text in an array field.

The corn job should be called 3-5 times to ensure all products are updated.

2 Likes