Creating direct link to product URL from variant/product ID

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

1 Like

You can use

https://<shopify_domain>/variants/<variant_id> for product detail page

or

https://<shopify_domain>/cart/<variant_id>:?storefront=true for adding the product to the cart and showing the cart page

1 Like

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?

1 Like

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.

1 Like

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" 
{...}