GraphQL admin api returns unpublished products in query "published_status:published"

timur-icoosoft
New Member
4 0 0

I'm trying to get published products:

query getProducts {
  products(first: 10, query: "published_status:published") {
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
    edges {
      cursor
      node {
        publishedOnCurrentPublication
        storefrontId
        id
        title
        handle
      }
    }
  }
}

Response contains products with publishedOnCurrentPublication === true and with publishedOnCurrentPublication === false. Is it correct?

Replies 7 (7)
Alex
Shopify Staff
1555 81 310

I believe this is correct. published_status:published is a pretty old value on the published_status field which just tells whether or not the product is published to the online store, it doesn't consider other channels. I do have a solution for you if you need to get products that are published to your channel. Try a query like this:

 

{
  products(first:10, query: "published_status:\"channel-name:visible\"") {
    edges {
      node {
        id
      }
    }
  }
}

 

Where channel-name is the name of your channel, lower cased, with dash separators where there would otherwise be spaces.

 

Let me know if that helps.

 

Cheers.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

timur-icoosoft
New Member
4 0 0

Alex, if I use published_status:"channel-name:visible" then I still get products with publishedOnCurrentPublication === false.

timur-icoosoft
New Member
4 0 0

I just found out that I’m not using channels, but private applications. How to filter by private application?

Alex
Shopify Staff
1555 81 310
Alex, if I use published_status:"channel-name:visible" then I still get products with publishedOnCurrentPublication === false.

Are you escaping the quotation marks? It wasn't parsing for me properly unless I was. Even after that, publishedOnCurrentPublication is only based on the calling API client. The product must be published to whatever channel your API credentials belong to when making the request to return as true. The query returns products that are published to a given channel name.

 

If you want to query based on your private app's visibility, you actually have to give it the API client ID. Unfortunately we don't surface that anywhere obvious at the moment, but with admin access, you can get it. Head to the products page and add a search filter for availability: your private app. The ID in the the URL when that filter is applied is your API client ID. You can then use that in your query strings over the graphql admin API.

Cheers.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

hmanlig
Tourist
5 0 1

Ignore this post....

 

i jumped the gun thinking the api client id is what i have below... then read your instructions on how to get api client id....

 

 

Below are my query and variable. The results still show publishedOnCurrentPublication:false

(where private-app-id, i got from see below

https://my-store.myshopify.com/admin/apps/private/private-app-id)

 

Query

 

 

query getFirstProductsWithCriteria($queryCriteria: String, $numProducts: Int) {
  products(query: $queryCriteria, first: $numProducts) {
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
    edges {
      cursor
      node {
        ...Product1
      }
    }
  }
}

fragment Product1 on Product {
id
legacyResourceId
title
onlineStoreUrl
handle
updatedAt
createdAt
publishedAt
publishedOnCurrentPublication
}

 

 

Query Variables

 

 

{
  "queryCriteria": "published_status:\"channel-name:visible\"",
"numProducts": 100 }

also tried

 

 

{
  "queryCriteria": "published_status:\"private-app-id:visible\""
}

 

 

hmanlig
Tourist
5 0 1

I'm looking for products that are hidden in my current sales channel (private app), AND are visible on the online store.

These queries don't seem to be working. Should these work?

 

"published_status:\"api-client-id:hidden\" AND published_status:\"online_store:visible\""

Or the reverse, products that are visible in my current sales channel, AND are hidden on the online store.

 

"published_status:\"api-client-id:visible\" AND published_status:\"online_store:hidden\""
matt_mechanic
Shopify Partner
6 0 4

Hey Everyone! 

Came across this post and was stumped why I couldn't get it to work.

It looks like this piece of information is no longer correct

Where channel-name is the name of your channel, lower cased, with dash separators where there would otherwise be spaces.

Those dashes need to be underscores.

This works:

{
  products (first: 100 query:"status:active AND published_status:'online_store:visible'") {
    edges {
      node {
        id
        title
      }
    }
  }
}

 

Matt Sodomsky
VP, Product & Strategy
Mechanic is a Shopify automation and development platform.
Try Mechanic for free today: https://apps.shopify.com/mechanic