Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
I would like to create a direct link to the live product on my Shopify store which will be created from the variant or product ID. This can be done through the API or URL redirect?
The variant/product ID is the only variable I have to work with, is this possible?
Thank you
You can use
https://<shopify_domain>/variants/<variant_id> for product detail page
or
https://<shopify_domain>/cart/<variant_id>:<quantity>?storefront=true for adding the product to the cart and showing the cart page
I have exactly the same question, but for the products without variants. Is it possible to access products without variants via URL containing just product id number?
I am not aware of such an option. But shopify creates a default variant for products where you have not explicitly created a variant. You can use that variant's ID for generating the link.
Where can I get this number of default variant for products without variants?
You can either use the Admin API or login to admin dashboard of your store and go to https://admin.shopify.com/store/<STORE_SLUG>/products/<PRODUCT_ID>.json
You can append the product page URL with ".json" in your browser to see the Variant ID and lots of other information for your product.
Use [SHOPIFY-PRODUCT-PAGE-URL].json and you will see "variants" in the json data listing.
Variant "0:" is the "base product" when there are no displayed variants, etc.:
product:
{...}
variants:
0:
id XXXXXXXXXXXXXX <~~ This is the default "Variant ID"
product_id YYYYYYYYYYYYY <~~ This is the Main "Product ID"
title "Default Title"
{...}