App reviews, troubleshooting, and recommendations
I want to fetch all variants of a product using shopify graphql api, but it seems like we have to define the number of variants or any other thing we want by using first an argument after the query. I want to get all variants of the product instead of defining a number of variants, how can this be possible?
const myproducts = await axios({ url: `https://${req.session.shop}/admin/api/2022-01/graphql.json`, method: 'post', headers: { "X-Shopify-Access-Token": req.session.token, }, data: { query: ` { product(id: "gid://shopify/Product/6829796196490") { title variants(first: 5) { edges { cursor node { selectedOptions { name value } media(first: 5) { edges { node { alt mediaContentType status __typename ... on MediaImage { id preview { image { originalSrc } } __typename } } } } } } pageInfo { hasNextPage } } } } `, } });
Hi @Leith
I think you can use REST API to get all variants for a product, it's easier than graphql API.
In Postman, you create a new get with this endpoint.
https://your-development-store.myshopify.com/admin/api/2021-10/products/{Product_ID}/variants.json
Then click send
The API will return all variants information for a product.
You can read our blog: Shopify API - Retrieve all variants for a product using Postman
Or watch the video for more overview: Shopify API | Lesson #23: Retrieve all variants for a product.
I hope this helps. Feel free to contact us if you need further assistance.
Thank you, I am now using rest API, but what about in the future I want to retrieve all products using graphql
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025