Reputation: 1471
I am an Android Developer and 0 knowledge in Wix. Is it possible to get a list of products from Wix Store to display it on Android app. I cannot find any documentation for Android.
This is my test website https://sakurafukuyoshi031.wixsite.com/juhachipawnshop/shop-1
I just want to know if it is possible to get the data so I can display it on my app from their API maybe by using javascript or the webview javascript injection methods Thanks
Upvotes: 2
Views: 2324
Reputation: 11
There's a way to expose a collection by creating an API using the wix-http-functions but it appears that it's limited to exposing custom collections - not Wix's native collections (Stores/Collections or Stores/Products). The example on the wix-http-functions is pretty self explanatory. Below a modified version of it:
// In http-functions.js
import {ok, notFound, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
// URL looks like:
// https://www.storename.com/_functions/storeProducts/1
// or
// https://user.wixsite.com/mysite/_functions/storeProducts/1
export function get_storeProducts(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
let pagesize=50;
// query a collection to find matching items
return wixData.query("Stores/Products")
// If you replace the "Stores/Products" with a custom collection name it works
.skip((request.path[0] - 1) * pagesize)
.limit(pagesize)
.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": `'${request.path[0]}' was not found`
};
return notFound(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
Unfortunately this produces an error with the native collections such as "Products"
{"error":{"name":"Error","errorGroup":"User","code":"WD_SCHEMA_DOES_NOT_EXIST"}}
(I could not find any documentation for the error - so this is where I got stuck)
If you then create a custom collection in Wix Code under "Database", export the products from "Stores/Products" into a CSV - and then import the CSV into the custom collection (and finally publish/sync the custom collection) you can workaround the apparent limitation of exposing the native product catalog via a custom API. It's not ideal - but could work if your catalog is not changing frequently.
Upvotes: 1
Reputation: 46
There isn't an API for Wix Stores just quite yet, but it's coming soon - https://www.wix.com/code/home/coming-soon
Upvotes: 1