Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Retail API] ProductServiceClient.listProductsAsync() pagination not working #5566

Closed
BitoSaga opened this issue Jul 21, 2024 · 1 comment
Closed

Comments

@BitoSaga
Copy link

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.

@BitoSaga BitoSaga changed the title ProductServiceClient.listProductsAsync() pagination not working [Retail API] ProductServiceClient.listProductsAsync() pagination not working Jul 21, 2024
@BitoSaga
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant