Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hi everybody, I'm trying to get published products from Storefront API but it returns unpublished products. Is it a bug? Or something wrong with query?
here is my query
{ products(first: 1, query: "published_status:published") { edges { cursor node { id title handle onlineStoreUrl vendor variants(first: 1) { edges { node { title image { src } price } } } } } } }
I also need to get products by Collections but I cannot add query in products, how do I get published products filter by a collection? This query gives error.
{ collectionByHandle(handle: "HANDLE") { products(first:1, query: "published_status:published") { edges { cursor node { id title handle onlineStoreUrl variants(first: 1) { edges { node { title image { src } price } } } } } } } }
The first query you are running is for GraphQL Admin API - Storefront API does not have a query filter of published_status. For Storefront API, it is either published to that channel and thus queryable or it isn't and thus you won't be able to query it no matter what. Do not confuse Admin APIs and Storefront API - the GraphQL schema is different.
1. Is there a way I can get published products filter by a collection from Storefront API?
2. If I have to use Admin graphql api can you please share an example of published products filter by a collection?
{ collectionByHandle(handle: "foo-collection") { products(first: 5) { edges { node { title } } } } }Will only return products in that collection that are published i.e. to the Online Store channel and publication date is less than now.
{ collectionByHandle(handle: "foo-collection") { products(first: 5) { edges { node { title publishedOnCurrentPublication } } } } }
Can you please explain why does this query return unpublished products? This is from storefront api https://help.shopify.com/en/api/custom-storefronts/storefront-api/reference/queryroot
{ products(first: 10) { edges { node { id onlineStoreUrl } } } }
@sabaraouf wrote:Can you please explain why does this query return unpublished products?
What is the URL you are querying?
/admin/api/graphql.json
or
/api/graphql
Thanks for the details answer. I only need to fetch the published products filtered by a collection.
I'm using api endpoint https://store.myshopify.com/api/graphql and this is my query as you shared
{ collectionByHandle(handle: "HANDLE") { products(first: 5) { edges { node { title onlineStoreUrl } } } } }
It returns some onlineStoreUrl: null which indicates product is unpublished. Why is this so?
Most likely because you have it published on your app channel. Check the product where you are seeing that onlineStoreUrl is null and you will probably find that it is published for your app name that you are using for Storefront API access.
You would need to unpublish it for your app channel and only have it in unpublished state for the Online Store like so
I see.. So I created a private app for Storefront API and gave it permissions to read the products and it attached all the products to the private app. Now is there an easy way to undo this operation for unpublished products? Any option in admin UI?
Or if you have plenty, bulk actions
Thank you. Yes I was looking for bulk operation option.