Getting product id and variant id in bulk

I am trying to get all my product id’s and variant id’s in bulk.

I tried to use this method to get my product id,

https://admin.shopify.com/store/my-store-name/variants.json?fields=id,product-id,price,compare_at_price&limit=250

it gives me the first 250 and then the tutorial i used said to use page=2 to get the next 250 and so on..

when i add &page=2 i get the following error

https:\/\/shopify.dev\/api\/usage\/pagination-rest for more information

why is shopify made it so damn difficult just to get a list of product id’s.

Can someone please help

Try this

let storeProducts = [];
let fetchCalls = [];
// Change i value a/to product total you have 250*6
 for (let i = 1; i <= 6; i++) {
    fetchCalls.push(fetch('/products.json/?limit=250&page=' + i));
}
Promise.all(fetchCalls)
    .then(responses => Promise.all(responses.map(response => response.json())))
    .then(productsArray => {
        // Flatten the array of arrays into a single array
        storeProducts = productsArray.flat();
 
        storeProducts.forEach(productsObj => {
            if (productsObj.products) {
                productsObj.products.forEach(product => {
                    console.log('Match found for product with title:', product);
                });
            } else {
                console.log('Invalid products structure in storeProducts');
            }
        });
 
    })
    .catch(error => console.error('Error:', error));