I am looking for a way to get best selling products of last month on a shopify store in javascript
. I know how to get best selling products of all time. Please see the code below.
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.exampleshopifysite.com/collections/all/products.json?sort-by=best-selling",
"method": "GET",
"headers": {
"Cache-Control": "no-cache"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
The url you've provided doesn't seem to provide relevant information.
But you can extract below information.
id,title,handle,body_html,published_at,created_at,updated_at,vendor,product_type,tags,variants,images,options
Example script ( link to fiddle )
var settings = {
"async": true,
"crossDomain": true,
"url": "https://spritude.com/collections/all/products.json?sort-by=best-selling",
"method": "GET",
}
$.ajax(settings).done(function (response) {
response.products.slice(0, 10).forEach(product => {
console.log(`ID: ${product.id}`);
console.log(`TITLE: ${product.title}`);
console.log(`HANDLE: ${product.handle}`);
console.log(`PUBLISHED AT: ${product.published_at}`);
console.log(`CREATED AT: ${product.created_at}`);
console.log(`UPDATED AT: ${product.updated_at}`);
console.log(`VENDOR: ${product.vendor}`);
console.log(`PRODUCT TYPE: ${product.product_type}`);
console.log(`TAGS: ${product.tags}`);
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.