Get total count of products
Counts the products in the project. Pass a filter body to count only the products that match specific conditions.
What this example does:
- Gets the total number of products
- Optionally filters by attribute conditions
- Uses the count for pagination
Prerequisites:
- A valid
PROJECT_URLandAPP_TOKENfor the OneEntry API - At least one product in the project
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.
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)
// To filter, use conditions like: [{ attributeMarker: 'price', conditionMarker: 'mth', conditionValue: 100 }]
const body: IFilterParams[] = [];
4. Get the count with Products.getProductsCount()
const data = await Products.getProductsCount(body);
if ('statusCode' in data) {
throw new Error(data.message);
}
console.log('Count data: ', data);
Result:
{
"totalAll": 12,
"totalInCategory": 0,
"totalInCategoryWithNested": 0
}
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)
// To filter, use conditions like: [{ attributeMarker: 'price', conditionMarker: 'mth', conditionValue: 100 }]
const body: IFilterParams[] = [];
// 4. Get the count with Products.getProductsCount()
const data = await Products.getProductsCount(body);
if ('statusCode' in data) {
throw new Error(data.message);
}
console.log('Count data: ', data);