Skip to main content

Get total count of products by page

This method returns the total number of products associated with a specific catalog page URL. It is useful for pagination when you need to know how many products exist on a given page, including or excluding nested child pages.

✅ Purpose of the scenario:

  • Get the count of products on a specific catalog page
  • Distinguish between direct products and products including nested pages
  • Use count for pagination on category or catalog pages

✅ What you need:

  • A valid PROJECT_URL and APP_TOKEN for authentication with the OneEntry API.
  • At least one catalog page with products in the project
  • The URL (page marker) of the target catalog page

📌 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 on the page without filtering.
  • totalInCategory counts only products directly on the given page; totalInCategoryWithNested also includes products on child pages.

📚 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 by page — This method returns the total number of products associated with a specific catalog page URL. It is useful for pagination when you need to know how many products exist on a given page, including or excluding nested child pages.

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 on the page)

Example:

// To filter, use conditions like: [{ attributeMarker: 'price', conditionMarker: 'mth', conditionValue: 100, isNested: false }]
const body: IFilterParams[] = [];

4. Call Products.getProductsCountByPageUrl() with getProductsCountByPageUrl()

Example:

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 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 on the page)
// To filter, use conditions like: [{ attributeMarker: 'price', conditionMarker: 'mth', conditionValue: 100, isNested: false }]
const body: IFilterParams[] = [];

// 4. Call Products.getProductsCountByPageUrl() with [getProductsCountByPageUrl()](/docs/products/#getProductsCountByPageUrl)
const count = await Products.getProductsCountByPageUrl('products', body);

if ('statusCode' in count) {
throw new Error(count.message);
}
console.log('Count data: ', count);