Getting channels of product

Solved

Getting channels of product

kindahome
Excursionist
13 3 2

Is it possible to get the channels of a product?

 

I already have the 2 permissions (publications and sales channel) to read and write

 

I have an online store and POS and more than 200 products linked to both of them

Tried a lot of fields, cant find the correct one!

Can you indicate me the field? Spent the last hours looking for that info at the documentation

 

My query:

// GET SINGLE PRODUCT BY HANDLE WITH ALL THE FIELDS
const singleProductWithMedia = `
query ($handle: String!) {
  productByHandle(handle: $handle) {
    id
    status
    title
    handle
    vendor
    productType
    metafields(first: 3) {
      edges {
          node {
              id
              key
          }
      }
    }
    media (first: 50) {
      edges {
        cursor
        node {
          alt
          status 
            ... on MediaImage {
              id
              image {
                id
                originalSrc
              }
            }                          
        }
      }
      pageInfo {
        hasNextPage
      }
    }
    variants (first: 10) {
      edges {
        cursor
        node {
          id
          title
          sku
          media (first: 1) {
            edges {
              node {
                ... on MediaImage {
                  id
                }
              }
            }
          }
          metafields(first: 20) {
            edges {
                node {
                    id
                    key
                }
            }
          }
          selectedOptions {
            name
            value
          }          
        }
      }
      pageInfo {
        hasNextPage
      }
    }
  }
}`;

 

 

Accepted Solution (1)

kindahome
Excursionist
13 3 2

This is an accepted solution.

The solution to get all channels:

 

Graphql

 

{
  channels (first: 50){
    edges{
      node{
        id
        name
      }
    }
  }
}

 

my server call:

 

async function testinggetchannel() {
  try {

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

              return res.data
      
        })

        console.log("THIS IS TESTING")
        console.log(myTesting)
    return myTesting
  } catch (err) {
    throw err
  }
}

View solution in original post

Replies 4 (4)

kindahome
Excursionist
13 3 2

I know its not hepfull, but using "publicationCount" gives me the channels that are active

 

If I disable the POS in a product, it counts 1

If I active both, it counts 2

 

Still can't find the way to list the channels name and if activated or not (maybe something like: POS: true) 

kindahome
Excursionist
13 3 2

This is an accepted solution.

The solution to get all channels:

 

Graphql

 

{
  channels (first: 50){
    edges{
      node{
        id
        name
      }
    }
  }
}

 

my server call:

 

async function testinggetchannel() {
  try {

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

              return res.data
      
        })

        console.log("THIS IS TESTING")
        console.log(myTesting)
    return myTesting
  } catch (err) {
    throw err
  }
}
StarProj
Visitor
2 0 1

Could you please tell me how you solved this problem ? how to get sales channels for a certain product ? Your example just displays a list of sales channels.

StarProj
Visitor
2 0 1

Anyway, I figured it out on my own, anyone who needs a solution can have it.

 

{
  product(id: "gid://shopify/Product/THIS_YOURE_ID_PRODUCT") {
    resourcePublicationsV2(first:10){
      edges{
        node{
          publication{
            app{
              id
              title
            }
          }
        }
      }
    }

  }
}