How to get productId / PublishingID from ProductVariant

icashout
New Member
2 0 0

Hello,

I'm searching for a product using SKU and ProductVariant GraphQL, I get the global ID back, but when i try to delete the product or try to get the publication using that ID and Product Mutation, it say invalid ID, how do i get the product id using the GID coming from variant search ??

 

Thank you

Venkat

 

0 Likes
CalD
Shopify Staff
Shopify Staff
91 8 12

Hey @icashout,

It sounds like you're trying to delete the Product using the ProductVariant's id?

You can use the Product connection on ProductVariant to get the parent product that the variant is associated with here: https://shopify.dev/docs/admin-api/graphql/reference/object/productvariant?api[version]=2020-07#type... . 

Sample query:

{
  productVariants(first:5, query:"sku:test123"){
    edges{
      node{
        product{
          id
        }
      }
    }
  }
}

then you should be able to delete the parent product using product id returned.

CalD | Developer Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog

0 Likes