What's the best way to fetch top-selling products from Shopify stores?

I’m trying to figure out how to get the most popular items from different Shopify stores. You know that page that shows the best-selling stuff? I want to grab that info, but it’s not the same for every store. Is there a way to do this that works for any Shopify site? Maybe some kind of API or a smart way to scrape the data? I’m not sure where to start. Any ideas would be super helpful!

Here’s a quick example of what I’m thinking:

def get_best_sellers(store_url):
    # Some magic code here
    return top_products

# Usage
store = 'coolshopifystore.com'
best_sellers = get_best_sellers(store)
print(best_sellers)

I’m open to any suggestions. Thanks in advance!

As someone who’s worked on a few Shopify-related projects, I can share some insights. While there’s no universal method to fetch top-selling products across all Shopify stores, you have a couple of options.

First, consider using Shopify’s REST API. Most stores have this enabled, and it allows you to fetch product data, including sales rankings. You’ll need to authenticate with each store individually, which can be a hurdle if you’re looking at multiple stores.

Another approach is web scraping, but this can be tricky. Shopify stores often have different layouts, and some use JavaScript to load product data dynamically. You’d need a robust scraper that can handle various store structures.

If you’re building something for your own store or have permission from store owners, the API route is more reliable. For a broader approach, you might need to combine API usage with some clever scraping techniques.

Remember, always respect each store’s terms of service and API usage limits. And be prepared for some stores to have measures in place to prevent data harvesting.

hey alex, u could try the shopify graphql api. its pretty powerful for grabbing product data. heres a quick example:

query {
  products(first: 10, sortKey: BEST_SELLING) {
    edges {
      node {
        title
        handle
      }
    }
  }
}

this’ll fetch the top 10 bestsellers. just make sure u got api access frm the store owner first!