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

Dear Community,

My goal is to connect my Wix Store’s Products-Database with Google Merchant using a synched feed. I am working with a 3rd Party Integration platform DataFeedWatch that can import different kind of dataset files such as json, xml, csv. Files can be either uploaded or linked to an url-exposed file.

I have successfully integrate my products using an uploaded csv file exported once from my Store/Product Database Collection. However, my goal is to connect directly an Endpoint json file using the HTTP Function API from Velo. This task was partially successfully but there are some missing fields in the Endpoint json. The most important field missing is “Collections” (see image below). With the collection field I am able to establish a mapping rule to Categorize Products. Defining Google Categories (Taxonmy) properly is essential to properly create Google Shopping campaign ads.

The exposed Endpoint url is here:
https://chicdog.cl/_functions-dev/product

In that json file the data of the field “Collections” is missing. I don’t really now why is missing and how frequently is this Endpoint data refreshed.

Below is the snippet code of the json file of the HTTP Functions.

Please help!!

  • Is something missing in my code that exclude the “Collections” field?
  • Is possible to define, security purposes, user and password to that Endpoint in the HTTP Functions API?

Products Database:

The code of the json backend-file is as follows (extracted from this article )

import {ok, notFound, serverError} from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;

export function get_product(request) {
let options = {
“headers” : {
“Content-Type” : “application/json”
}
};
// query a collection to find matching items
return wixData.query( “Stores/Products” )
.find()
.then( (results) => {
// matching items were found
if (results.items.length > 0 ) {
options.body = {
“items” : results.items
};
return ok(options);
}
// no matching items found
options.body = {
“error” : not found
};
return notFound(options);
} )
// something went wrong
. catch ( (error) => {
options.body = {
“error” : error
};
return serverError(options);
} );
}

Categorize Products in DataFeedWatch:

Hello @cramdohr !
I have the same problem ! I succeeded to get the json of my products and that of my collections but I can’t make the link between the two. There are no fields in the json of the products that refer to their collections.

Have you found a solution since then?

Thank you.

1 Like

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