You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`const productClient = new ProductServiceClient({
'credentials': credentials,
'autoPaginate': false, // I add this according to some other issue previously reported
});
async function listProducts() {
// Construct request
const request = {
'parent': 'projects/xxxx/locations/global/catalogs/default_catalog/branches/0',
'pageSize': 4,
'autoPaginate': false, // add this again to ensure it's effective because it's not documented
};
// Run request
const iterable = productClient.listProductsAsync(request);
const result = [];
for await (const response of iterable) {
result.push(response);
}
return result;
}
`
However, I always get the full list of all products no matter pageSize. Please help if anyone knows the solution.
The text was updated successfully, but these errors were encountered:
BitoSaga
changed the title
ProductServiceClient.listProductsAsync() pagination not working
[Retail API] ProductServiceClient.listProductsAsync() pagination not working
Jul 21, 2024
for those who are interested, async method will return an iterable that may return all items without additional control. I am still learning how to make it work to return a page of items each time. but for non async method, like listProducts(), you can add {autoPaginate:false} as the 2nd argument to the method call, like productClient.listProducts(request, {autoPaginate:false}). It works as expected. Please refer to: Auto Pagination. I will close this issue.
My code is like this:
`const productClient = new ProductServiceClient({
'credentials': credentials,
'autoPaginate': false, // I add this according to some other issue previously reported
});
async function listProducts() {
// Construct request
const request = {
'parent': 'projects/xxxx/locations/global/catalogs/default_catalog/branches/0',
'pageSize': 4,
'autoPaginate': false, // add this again to ensure it's effective because it's not documented
};
// Run request
const iterable = productClient.listProductsAsync(request);
const result = [];
for await (const response of iterable) {
result.push(response);
}
return result;
}
`
However, I always get the full list of all products no matter pageSize. Please help if anyone knows the solution.
The text was updated successfully, but these errors were encountered: