Hi, I am developing a shopify app and I want get store products by ids using this api call - (https://shopify.dev/docs/api/admin-rest/2024-01/resources/product#get-products?ids=632910392,921728736).
The issue is as follows when I make the request with query parameter limit set to 250 I get only 50 products returned as a response. The thing is I can see that the limit in response is correctly set to 250, however I am only getting 50 products. Has someone ran into this issue before?
Can I see the code you are using to make the request?
/* CLIENT PROVIDER */
const restClient = async ({ req, res, isOnline }) => {
const session = await fetchSession({ req, res, isOnline });
const client = new shopify.clients.Rest({ session });
const { shop } = session;
return { client, shop, session };
};
const clientProvider = { graphqlClient, restClient };
export default clientProvider;
// rest client
const { client } = await clientProvider.restClient({
req,
res,
isOnline: false,
});
/* REQUEST */
let requestBody = {
path: products.json?ids=${chunk.join(',')},
query: { limit: 250 }
}
let data = await client.get(requestBody);
chunk is an array of product ids I confirmed the length of the chunk is 250 as it should be
I would try and add a little bit of error handling for this issue:
/* CLIENT PROVIDER */
// ... existing code ...
/* REQUEST */
try {
let requestBody = {
path: `products.json?ids=${chunk.join(',')}`,
query: { limit: 250 }
}
let response = await client.get(requestBody);
if (response.headers && response.headers.link) {
console.log('More products available for pagination');
}
let data = response.body;
// Additional processing of data
} catch (error) {
console.error('Error fetching products:', error);
// Handle the error appropriately
}
Shopify API uses pagination for large sets of data. If the response includes a link header, it indicates that there is more data available, and you will need to make additional requests to retrieve the remaining data.
Thanks, I am doing it that way of course, I think I found the solution you just have to specify the limit parameter in path before the product ids you want to retrieve like this:
const data = await client.get({ path: products.json?limit=${CHUNK_SIZE}&ids=${chunk.join(',')} });
I would post this on the Shopify GitHub under issues and see if this might be a bug?
Just from my experience, this shouldn’t normally be a thing. You should be able to still use limit if you specify it after the ids.
I don’t see anything in the documentation that states that. But I could be totally wrong!
Glad you got it fixed.