Find product, variant and customer IDs

Where Shopify product, variant and customer IDs live: the admin URL, the .json trick, a variant ID report, the storefront .js URL, Liquid and the Admin API.

Product
admin URL …/products/<ID>
Variant
…/variants/<ID> or .json
Bulk
Report with Product variant ID
API form
gid://shopify/ProductVariant/<ID>
Last checked

In short

A Shopify product ID is the number after /products/ in the admin URL, and a variant ID the number after /variants/ when you open a variant. For a product without variants, add .json to the product page URL and read variants > id. A custom report with the Product variant ID dimension lists them all. In themes use product.id, variant.id and customer.id; the Admin API wraps the same numbers in GIDs.

How to use it

  1. Product: open it in the admin and copy the number at the end of the URL.
  2. Variant: click the variant on the product page and copy the number after /variants/; for a product without variants, add .json to the URL.
  3. Many variants: Analytics > Reports > New exploration, add the Product variant ID dimension, then save or export.
  4. Customer: in theme code use {{ customer.id }} for the logged-in customer; in the Admin API, query customers by email and read the GID.

Code

customer-id.graphql
# Admin API: find a customer's ID by email. The numeric ID is the last part of the GID.
query CustomerIdByEmail($query: String!) {
  customers(first: 1, query: $query) {
    nodes {
      id
      defaultEmailAddress {
        emailAddress
      }
    }
  }
}
show-ids.liquid
{%- comment -%}
  Prints IDs while you build theme code. Keep it in an unpublished theme or
  behind request.design_mode so customers never see it.
{%- endcomment -%}
{%- if request.design_mode -%}
  <pre>
product.id:                {{ product.id }}
selected variant id:       {{ product.selected_or_first_available_variant.id }}
all variant ids:           {{ product.variants | map: 'id' | join: ', ' }}
{%- if customer %}
customer.id (logged in):   {{ customer.id }}
{%- endif %}
  </pre>
{%- endif -%}
where-to-find.txt
# Product ID: the number after /products/ in the admin URL
https://admin.shopify.com/store/your-store/products/1234567890

# Variant ID: open the variant; the number after /variants/
https://admin.shopify.com/store/your-store/products/1234567890/variants/12345678901234

# Product without variants (or all variant IDs at once): add .json to the product URL
https://admin.shopify.com/store/your-store/products/1234567890.json
-> "product" > "variants" > "id"

# Many variant IDs: Analytics > Reports > New exploration
Metric: Percent of inventory sold
Dimensions: Product title, Product variant title, Product variant ID
-> Save or export

# From the storefront (no admin access needed)
https://your-store.com/products/example-product.js     -> "id" and "variants[].id"
https://your-store.com/products/example-product?variant=12345678901234

# GraphQL Admin API IDs are the same numbers inside a GID
gid://shopify/Product/1234567890
gid://shopify/ProductVariant/12345678901234
gid://shopify/Customer/9876543210
customer-id.variables.json
{"query": "email:\"name@example.com\""}

Written by Lintel. MIT license: free to use in your own store and in client work.

Limits and edge cases

  • A product without variants still has one variant (titled Default Title) with its own ID; cart links need that variant ID, not the product ID.
  • Changing a product’s option values in a CSV import creates new variant IDs.
  • The storefront /products/<handle>.js URL also lists every variant ID, without admin access.
  • Shopify is rolling out a redesigned product page, so where you click to open a variant may differ.

Questions

How do I find a variant ID in Shopify?
Open the variant in the admin and copy the number after /variants/ in the URL, or add .json to the product page URL.
How do I find the variant ID of a product with no variants?
Add .json to the product’s admin URL and read product > variants > id. It’s the “Default Title” variant.
How do I get all variant IDs at once?
Create a report exploration with Product title, Product variant title and Product variant ID, then export it.
How do I find a customer ID?
In Liquid, customer.id for the logged-in customer. Through the Admin API, query customers with email:"…" and read the ID from the GID.
  • Checked on a Shopify store on the date shown. Shopify changes its admin often; if a step looks different, the idea usually still works.
  • Examples use placeholder IDs and your-store.myshopify.com. Replace them with your own.
  • MIT license for the code snippets.

Need this built, tested and maintained for your store? See Shopify development.

Have something to build? Let’s talk it through.

Taking a limited number of projects at a time. Every brief is read by an engineer, not a salesperson.

Gencer KarakayaShopify Engineer

An engineer reads your brief, and we reply by email.