Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

How to do pagination Node JS Shopify API.

How to do pagination Node JS Shopify API.

KaneT36
Shopify Partner
4 0 1

Hi There,
I've spent days trying to figure out an issue I'm having with the shopify api for nodeJS.

How can I use pagination when using the node client "Customer.search()" from here https://shopify.dev/api/admin-rest/2022-04/resources/customer#get-customers.

 

Here is what I'm using at the moment:

const customerDetails = await Customer.search({
session,
query: req.query.search ? req.query.search : null,
limit: 50,
// Nothing seems to work here to paginate, nor is there any documentation surrounding this feature on this specific client
});


The limit is only 250 customers and I need to be able to paginate through a few thousand.

Best,

Kane

Replies 3 (3)

PTP
Shopify Partner
14 0 2

Did you ever figure this out? I'm trying to get pagination to work as well. Not much from the docs...

BrandlyAndCo
Shopify Partner
1 0 0

Hello,

 

I'm having issues with this pagination too, I've made a nodejs and express app that can request products on an endpoint and wanted to perform the paginated request for the second page, but I can't manage the way client-side can tell my backend to request the next page

I've tried to make a GET request on the link given by the API from the headers but I've a CORS error 

 

Does someone know anything ? The documentation is too general about pagination and there is no example

mingpro711
Shopify Partner
1 0 0

Take a look this doc https://shopify.dev/docs/api/usage/pagination-rest.

 

Below is an working example to fetch all inventory levels by location ids. But I think other pagination should be similar. Hope it still helps after one year. LOL

 

async getAllInventoryLevelsByLocationIds(locationIds: string[]):Promise<InventoryLevel[]> {
const session = this.getSession();
let result:InventoryLevel[] = [];

// Get the first page
let response = await this.shopify.rest.InventoryLevel.all({
session,
location_ids: locationIds.join(','),
limit: 250
});
result = result.concat(response.data);

// Get the following pages. Can NOT pass in location_ids to get next pages
let nextPageInfo = response.pageInfo?.nextPage?.query?.page_info;
while(nextPageInfo) {
response = await this.shopify.rest.InventoryLevel.all({
session,
limit: 250,
page_info: nextPageInfo,
});

result = result.concat(response.data);
nextPageInfo = response.pageInfo?.nextPage?.query?.page_info;
}

return result;
}