Get total count of products
This method returns the total number of products in your project. You can optionally pass a filter body to count only products matching specific conditions.
✅ Purpose of the scenario:
- Get the total number of products
- Optionally filter by attribute conditions
- Use count for pagination or availability checks
✅ What you need:
- A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
- At least one product in the project
📌 Important:
- These examples do not include error handling.
- You can manage errors using a try-catch block or by employing a construction like await Promise.catch((error) => error).
- Pass an empty array [] to count all products without filtering.
📚 See in documentation:
📦 SDK reference:
Try it live
Run this method interactively in the JS SDK sandbox — connect your Project URL and App Token on first visit, then open:
- Get total count of products — This method returns the total number of products in your project. You can optionally pass a filter body to count only products matching specific conditions.
Scenario
1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN
Example:
import { defineOneEntry } from 'oneentry';
import { IFilterParams } from 'oneentry/dist/products/productsInterfaces';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Creating an API client with defineOneEntry()
Example:
const { Products } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Optionally define a filter body (empty array = all products)
Example:
// To filter, use conditions like: [{ attributeMarker: 'price', conditionMarker: 'mth', conditionValue: 100, isNested: false }]
const body: IFilterParams[] = [];
4. Call Products.getProductsCount() with getProductsCount()
Example:
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 from SDK and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import { IFilterParams } from 'oneentry/dist/products/productsInterfaces';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
// 2. Creating an API client with [defineOneEntry()](/docs/index/#Installation)
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, isNested: false }]
const body: IFilterParams[] = [];
// 4. Call Products.getProductsCount() with [getProductsCount()](/docs/products/#getProductsCount)
const data = await Products.getProductsCount(body);
if ('statusCode' in data) {
throw new Error(data.message);
}
console.log('Count data: ', data);