> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CountProducts

# Package: catalogV3

# Namespace: CatalogApi

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/count-products.md

## Permission Scopes:
Read products in v3 catalog: SCOPE.STORES.PRODUCT_READ
Product v3 read admin: SCOPE.STORES.PRODUCT_READ_ADMIN

## Introduction

Counts the number of products that match the provided filtering.

---

## REST API

### Schema

```
 Method: countProducts
 Description: Counts the number of products that match the provided filtering.
 URL: https://www.wixapis.com/stores/v3/products/count
 Method: POST
 This method is cacheable: Responses from this method are cached for optimal performance.
 Method parameters:
   param name: filter | type: filter | description: Filter object.  
   param name: returnNonVisibleProducts | type: returnNonVisibleProducts | description: Whether to return non-visible products (`visible:false`). Your app must have the 'Product v3 read admin' (`SCOPE.STORES.PRODUCT_READ_ADMIN`) permission scope.  Default: `false`  
   param name: search | type: SearchDetails    
        - name: mode | type: Mode | description: Defines how separate search terms in `expression` are combined  
             - enum:
             -     OR: Any of the search terms must be present
             -     AND: All search terms must be present
        - name: expression | type: string | description: Search term or expression  | validation: maxLength 100
        - name: fields | type: array<string> | description: Fields to search in. If the array is empty, all searchable fields are searched. Use dot notation to specify a JSON path. For example, `order.address.streetName`.  | validation: maxItems 20, maxLength 200
        - name: fuzzy | type: boolean | description: Whether to enable the search function to use an algorithm to automatically find results that are close to the search expression, such as typos and declensions.  
 Return type: CountProductsResponse
  - name: count | type: integer | description: Total number of products.  

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: NO_PERMISSION_TO_INCLUDE_NOT_VISIBLE_PRODUCTS | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions.
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: NO_PERMISSION_TO_READ_MERCHANT_DATA | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions.


```

### Examples

### CountProducts that satisfy filter or search
```curl
curl -X POST 'https://www.wixapis.com/stores/v3/products/count' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
      "filter": {
        "$and": [
          {
            "allCategoriesInfo.categories": {
              "$matchItems": [
                {
                  "id": {
                    "$eq": "643721c3-446e-47f3-87ee-0a58d6842d48"
                  }
                }
              ]
            }
          },
          {
            "productType": {
              "$eq": "PHYSICAL"
            }
          },
          {
            "visible": {
              "$eq": false
            }
          },
          {
            "brand.id": {
              "$eq": "4a16d28d-1736-41f0-87d8-995f6d9a5bdd"
            }
          },
          {
            "infoSections.id": {
              "$hasSome": [
                "59954f23-fbcd-42e5-ba61-7c8cf9d8b409"
              ]
            }
          },
          {
            "actualPriceRange.minValue.amount": {
              "$gt": 3
            }
          },
          {
            "actualPriceRange.minValue.amount": {
              "$lt": 120
            }
          },
          {
            "inventory.availabilityStatus": {
              "$in": [
                "OUT_OF_STOCK",
                "PARTIALLY_OUT_OF_STOCK"
              ]
            }
          },
          {
            "options.choicesSettings.choices.choiceId": {
              "$hasSome": [
                "4498b805-2aed-43fb-b478-989c906c19cd"
              ]
            }
          }
        ]
      }
    }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.stores.productsV3.countProducts(options)
 Description: Counts the number of products that match the provided filtering.
 This method is cacheable: Responses from this method are cached for optimal performance.
 Method parameters:
   param name: options | type: CountProductsOptions  none  
        - name: filter | type: object | description: Filter object.  
        - name: search | type: SearchDetails | description: Free text to match in searchable fields.  
           - name: mode | type: Mode | description: Defines how separate search terms in `expression` are combined  
                 - enum:
                 -     OR: Any of the search terms must be present
                 -     AND: All search terms must be present
           - name: expression | type: string | description: Search term or expression  | validation: maxLength 100
           - name: fields | type: array<string> | description: Fields to search in. If the array is empty, all searchable fields are searched. Use dot notation to specify a JSON path. For example, `order.address.streetName`.  | validation: maxItems 20, maxLength 200
           - name: fuzzy | type: boolean | description: Whether to enable the search function to use an algorithm to automatically find results that are close to the search expression, such as typos and declensions.  
        - name: returnNonVisibleProducts | type: boolean | description: Whether to return non-visible products (`visible:false`). Your app must have the 'Product v3 read admin' (`SCOPE.STORES.PRODUCT_READ_ADMIN`) permission scope.  Default: `false`  
 Return type: PROMISE<CountProductsResponse>
  - name: count | type: integer | description: Total number of products.  

 Possible Errors:
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: NO_PERMISSION_TO_INCLUDE_NOT_VISIBLE_PRODUCTS | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions.
   HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: NO_PERMISSION_TO_READ_MERCHANT_DATA | Description: The [identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md) used to call the method doesn't have the required permissions.


```

### Examples

### Count products with filter conditions
Count products with multiple filter conditions including category, type, visibility, brand, info sections, price range, inventory status, and options

```javascript
import { productsV3 } from "@wix/stores";

const filter = {
  $and: [
    {
      "allCategoriesInfo.categories": {
        $matchItems: [
          {
            id: {
              $eq: "643721c3-446e-47f3-87ee-0a58d6842d48"
            }
          }
        ]
      }
    },
    {
      productType: {
        $eq: "PHYSICAL"
      }
    },
    {
      visible: {
        $eq: false
      }
    },
    {
      "brand.id": {
        $eq: "4a16d28d-1736-41f0-87d8-995f6d9a5bdd"
      }
    },
    {
      "infoSections.id": {
        $hasSome: ["59954f23-fbcd-42e5-ba61-7c8cf9d8b409"]
      }
    },
    {
      "actualPriceRange.minValue.amount": {
        $gt: 3
      }
    },
    {
      "actualPriceRange.minValue.amount": {
        $lt: 120
      }
    },
    {
      "inventory.availabilityStatus": {
        $in: ["OUT_OF_STOCK", "PARTIALLY_OUT_OF_STOCK"]
      }
    },
    {
      "options.choicesSettings.choices.choiceId": {
        $hasSome: ["4498b805-2aed-43fb-b478-989c906c19cd"]
      }
    }
  ]
};

async function countProducts() {
  const response = await productsV3.countProducts({ filter });
}

/* Promise resolves to:
 * {
 *   "count": 1
 * }
 */


```

### countProducts (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { productsV3 } from '@wix/stores';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { productsV3 },
  // Include the auth strategy and host as relevant
});


async function countProducts(options) {
  const response = await myWixClient.productsV3.countProducts(options);
};
```

---