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
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024