Programmatically creating a buy button

dwainebest
New Member
2 0 0
Hello All,
I've got a Gatsby site with Contentful as CMS and Shopify as Ecommerce. I'm trying to accomplish automatically creating a buy button, but the Shopify id that's provided in the Graphql is different from the id that Shopify uses in its button creation. At least, that's what I can discern. For instance, when getting the product id from Graphql:
...
"id": "Shopify__Product__Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzYxMTU4OTc2MzkwOTA=",
"shopifyId": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzYxMTU4OTc2MzkwOTA="
},
...
 
But the buy button id looks like this:
 
...
ui.createComponent('product', {
id: '6115897639090',
...
 
It also provides an id for the div, which I assume helps with verifying the correct product.
 
I just don't see how to get it all to relate and automatically create buy buttons. Individually creating them for 1000+ products isn't realistic. Is there a way to call the Buy link and provide it the Graphql id?
Is there perhaps a better way to go about this? I want the cart to open and other functionality there, and I'm trying to save a little time in implementation, so that's why I thought just automatically creating Buy Buttons would be viable. But is it?
 
Cheers.
0 Likes
dwainebest
New Member
2 0 0

Just figured it out. Here's the other thread to help with the solution:

https://community.shopify.com/c/Shopify-APIs-SDKs/Storefront-API-variantId-different-than-Rest-API-v...

0 Likes