Out now! Check out the Poll results: Do you have a Shopify store?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Getting referenced variant with GraphQL

Getting referenced variant with GraphQL

CamillaGejl
Shopify Partner
1 0 1

Hi!

 

I'm using the Storefront API and Accentuate to try to get my hands on a specific variant, but it won't work for me.

 

THE SHORT VERSION: When I select a variant on the website, I get the url: (... url ...)?variant=31696763027492. How do I get my hands on these numbers after the = for the variant in GraphQL? It does not match the ID.


THE LONG VERSION...

In a product variant, I reference to a variant of another product (with Accentuate). What I need to get out is the variant that I am referencing to.

When I pull out the variant that is being referenced to in the product (as metafield, with GraphQL), I get this:

 

{
"key": "products_in_package",
"value": "pakke-produkt-gavepose:31696763027492"
}

 

My problem is the numbers after : in the value. I've found that these are the number that come after the URL of the product when choosing the variant on the "actual" shopify website ((... url ...)?variant=31696763027492), but I can't see how I can use them, since I can't find these numbers on the actual variant through GraphQL.

It does not match the 'id' or anything else I could find on the variant. Neither can I include the numbers if I try to get productByHandle.

So, does anyone have any ideas on how I can I use it to get the actual product variant through GraphQL? Or ideas on what else I can do to connect a specific product variant to another product variant?

Reply 1 (1)

Nesters
Shopify Partner
19 1 19

I assume you are confused by Storefront API id's.

 

You can read about it more here: https://shopify.dev/docs/storefront-api/reference/scalar/#id-2020-01

 

Essentially, the id in Storefront API is a base64 encoded version of the id in a format gid://shopify/ProductVariant/<your_variant_id>

Contact me: mail@nesters.me
Technical solutions / integration / headless ecommerce.
Latest post: Benefits of JAMstack ecommerce