Get total count of products by page
Counts the products on a catalog page by its URL, with or without nested child pages. Use the count for pagination.
What this example does:
- Gets the count of products on a specific catalog page
- Compares the count on the page itself with the count that includes nested pages
- Uses the count for pagination on category or catalog pages
Prerequisites:
- A valid
PROJECT_URLandAPP_TOKENfor the OneEntry API - At least one catalog page with products in the project
- The URL of the target catalog page (the part after the last
/, for example,products)
Notes:
- By default (
isShell: true) the SDK returns an error object instead of throwing, so check the result, e.g.'statusCode' in result. WithisShell: falseit throws, and you handle errors with try/catch. See Errors. - Pass an empty array (
[]) to count all products on the page without filtering. totalInCategorycounts only products directly on the given page;totalInCategoryWithNestedalso includes products on child pages.isNestedin filter conditions is ignored by this method.
Platform docs:
SDK reference:
Try it live
Run this example in the JS SDK sandbox. Connect your Project URL and App Token on first visit, then open:
Scenario
1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import type { IFilterParams } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
2. Create an API client with defineOneEntry()
const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Optionally define a filter body (empty array = all products on the page)
// To filter, use conditions like: [{ attributeMarker: 'price', conditionMarker: 'mth', conditionValue: 100 }]
const body: IFilterParams[] = [];
4. Get the count with Products.getProductsCountByPageUrl()
const count = await Products.getProductsCountByPageUrl('products', body);
if ('statusCode' in count) {
throw new Error(count.message);
}
console.log('Count data: ', count);
Result:
{
"totalAll": 12,
"totalInCategory": 3,
"totalInCategoryWithNested": 3
}
Final example
// 1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import type { IFilterParams } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
// 2. Create an API client with defineOneEntry()
const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Optionally define a filter body (empty array = all products on the page)
// To filter, use conditions like: [{ attributeMarker: 'price', conditionMarker: 'mth', conditionValue: 100 }]
const body: IFilterParams[] = [];
// 4. Get the count with Products.getProductsCountByPageUrl()
const count = await Products.getProductsCountByPageUrl('products', body);
if ('statusCode' in count) {
throw new Error(count.message);
}
console.log('Count data: ', count);