Check if product is published on sale channels like google or facebook by Graphql API

abba122
Shopify Partner
4 0 2

Hello,

I was trying to use publishedOnPublication or resourcePublicationsV2 from Graphql API to check if a product is published on certain sale channels, but I got access denied for scope read_publications. As I don't have a plan to upgrade to Shopify plus plan or install other apps, is there any other way that I can check or filter whether products are published on specific sale channels like google or facebook? 

 

Sincerely,

Ab

Replies 6 (6)

its_me_dhanesh
Visitor
2 0 2

Hi,

How did you do that, could you please able to share it here? I am also struggling ;(

kindahome
Excursionist
13 3 2

do you solved this problem?

abba122
Shopify Partner
4 0 2

Sadly no... 😞

Here is what we did so far. Hope it may be helpful somehow. As we were using Mytrixify app for feed upload, we ended up using the published and scope to control channels. We only used it to decide if products go to all channels or just the online store. In google merchant content API, we use custom value and feed rule to filter if products sell on buy on google. Our fb sale channel still has some problems, so we didn't take care of fb publishing yet.  Screenshot from 2021-08-24 17-30-42.png 

kindahome
Excursionist
13 3 2

Thanks. It makes sense. But I'm sad there's no way to get that information more easily

 

I have an easy situation to resolve. Just need to publish to all channels or remove from all channels (in a specific situation).

 

But in the future I will need to do that

kindahome
Excursionist
13 3 2

Don't know if this helps, but I will share what I discovered with you and share my code adapted to what I needed

 

 

Imagine: I need to check if product XPTO is published at Online Store

 

First of all, I get the GID of 'Online Store'. Get all channels, loop and save the ID

Second, search the product using the handle to get the GID

Finally, create a structure with that GID to execute query.

 

Sorry for all the code:

 

async function isPublishedIn(channel_name, resource){
  let channelsList = await getAllChannels()

  let channel_gid = null

  // If there are channels,
  // lets look for the channel we want
  // if the channel exists, save the GID
  // IF NOT channel is null
  if(channelsList != null){
    if(channelsList.length > 0){
      for (let channelData of channelsList) {
        if(channelData.node.name == channel_name){
          channel_gid = channelData.node.id
          console.log("INFORMAÇÃO DO CANAL")
          console.log(channelData)
        }
      }
    }
  }

  // if channel_gid is null, the channel is not available or not exist. Return false
  if(channel_gid == null)
    return false

  // Channel exists, we have the GID. Execute QUERY to check
  // Generate handle data structure
  let searcherVariable = {
    "handle": resource.created[0].handle
  }
  
  // Get global product to get the GID
  let globalProduct = await shopifyHelpers.getSingleSlim(searcherVariable, true)



  // Generate handle data structure
  searcherVariable = {
    "id": globalProduct.id,
    "channel_id": channel_gid
  }

  console.log('***************************')
  console.log("CHECK IF PRODUCT IN CHANNEL")
  console.log('***************************')
  console.log("-> ESTRUTURA: ")
  console.log(searcherVariable)

  // Check product
  let singleProductData = await shopifyHelpers.isProductInChannel(searcherVariable, true)
  
  console.log('***************************')
  console.log('***************************')
  
  if(singleProductData == null)
    return false

  return singleProductData.data.product.publishedOnChannel
}

This is my "helper" that I use as a intermediary between Server and Query:

 

// CHECK IF PRODUCT EXISTS IN CHANNEL
async function isProductInChannel(variables) {
  try {

    //COST - 37
    await getApiPoints(37);
    
    let result = await axios.post('http://localhost:3060/graphql', {"query": gq.isProductInChannel, "variables":variables}
            ).then( async (res) => {  
			
              console.log(res.data)

              return res.data
      
        })

        
    return result
  } catch (err) {
    throw err
  }
}

 

My query:

 

// PRODUCT EXISTS IN CHANNEL
const isProductInChannel = `
query ($id: ID!, $channel_id: ID!) {
  product(id: $id) {
    publishedOnChannel(channelId: $channel_id)
  }
}`

 

I dont know if you can see my other posts, but I have there the solutions to get GID from channel, get all channels, etc

guest4
Shopify Partner
82 6 20

For posterity: 

write_publications and read_publications are no longer just for Shopify Plus.