Shopify Products API not include unpublished products?

Highlighted
Tourist
8 0 0

Hi!

Currently the API is 

ShopifyAPI::Product.find(:all, params: { limit: limit })

Is there a method to grab only products that are active (published_at not nil?) ? I'm working with some stores that have THOUSANDS of inactive products and when I run a command like:

products = ShopifyAPI::Product.find(:all, params: { limit: limit })
product_list = []
product_list << products
while products.next_page?
 products = products.fetch_next_page
 product_list << products
end

It's looping through hundreds of pages of products that are disabled from the store. Thus slowing everything down.

 

I can iterate on the active products once I build the array with

live_products = product_list.select {|item| item.published_at.present? }

But I was hoping there is a better way with a method while getting the products.

 

Thanks for your help!

0 Likes
Highlighted
Shopify Partner
1780 211 370

You can use a query like this:

query getProducts {
  products(first: 10, query: "published_status:published") {
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
    edges {
      cursor
      node {
        publishedOnCurrentPublication
        storefrontId
        id
        title
        handle
      }
    }
  }
}
Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
Tourist
8 0 0

@Visely-Team 

 

Ya, that's through GraphQL. How would I use that with a ruby on rails application?

0 Likes
Highlighted
Shopify Partner
1780 211 370

You can use GraphQL.client to parse and query Shopify, here is an example - https://github.com/Shopify/shopify_api#6a-making-requests-to-the-graphql-api 

That would give you a more flexibility to build custom queries as the one I have shared above.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
Tourist
8 0 0
Ok! How would pagination work? What’s the query to get all products (and the product’s attributes). I don’t see that in the examples.
Thanks for the help!
0 Likes