> 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`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# CountParticipants

# Package: audiences

# Namespace: AudienceService

# Method link: https://dev.wix.com/docs/api-reference/business-management/notifications/audiences/audience-v1/count-participants.md

## Permission Scopes:
Set Up Automations: SCOPE.CRM.SETUP-AUTOMATIONS

## Introduction

Retrieves the count of participants for one or more audiences, broken down per audience/provider.

If an audience's provider doesn't implement `countParticipants`, the returned `count` for that audience is `1` instead of an exact number. If a provider implements `countParticipants` but fails to return a count, the request fails.

---

## REST API

### Schema

```
 Method: countParticipants
 Description: Retrieves the count of participants for one or more audiences, broken down per audience/provider.  If an audience's provider doesn't implement `countParticipants`, the returned `count` for that audience is `1` instead of an exact number. If a provider implements `countParticipants` but fails to return a count, the request fails.
 URL: https://www.wixapis.com/audience-service/v1/count-participants
 Method: POST
 Method parameters:
   param name: audiences | type: array<audiences> | description: Audiences to count participants for. Each audience specifies a provider, identified by `audienceProviderId`, and the input data that provider needs to resolve participants.  | validation: maxItems 20
              - name: audienceProviderId | type: string | description: identifier of the provider  | validation: minLength 1, maxLength 100
              - name: audienceProviderData | type: object | description: audience provider data is needed in order to list participants of each provider  
   param name: locationIds | type: array<locationIds> | description: Location GUIDs used to filter for participants relevant to these locations.  | validation: maxItems 30, format GUID
 Return type: CountParticipantsResponse
  - name: audienceParticipantCount | type: array<ParticipantCount> | description: Participant count broken down by audience provider, based on the audience configuration given in the request.  If a provider doesn't implement `countParticipants`, its `count` is `1` instead of an exact number.  | validation: maxItems 20
     - name: audienceProviderId | type: string | description: GUID of the provider, in the format `{appId}_{key}`.  | validation: minLength 1, maxLength 100
     - name: count | type: integer | description: Total count of participants for the provider.  
     - name: type | type: ParticipantType | description: Type of the participant.  
         - enum: WIX_USER, CONTACT, ANONYMOUS

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_PROVIDER_ID | Description: The audience's `audienceProviderId` isn't in the expected `{appId}_{key}` format.


```

### Examples

### Estimate how many contacts are labeled VIP Customer
Retrieves the number of participants in the same audience of contacts labeled `custom.vip-customer`, without resolving the participants themselves.

```curl
curl -X POST \
'https://www.wixapis.com/audience-service/v1/count-participants' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "audiences": [
    {
      "audienceProviderId": "74bff718-5977-47f2-9e5f-a9fd0047fd1f_labels",
      "audienceProviderData": {
        "labelIds": ["custom.vip-customer"]
      }
    }
  ]
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.audiences.audiences.countParticipants(options)
 Description: Retrieves the count of participants for one or more audiences, broken down per audience/provider.  If an audience's provider doesn't implement `countParticipants`, the returned `count` for that audience is `1` instead of an exact number. If a provider implements `countParticipants` but fails to return a count, the request fails.
 Method parameters:
   param name: options | type: CountParticipantsOptions  none  
        - name: audiences | type: array<Audience> | description: Audiences to count participants for. Each audience specifies a provider, identified by `audienceProviderId`, and the input data that provider needs to resolve participants.  | validation: maxItems 20
           - name: audienceProviderId | type: string | description: identifier of the provider  | validation: minLength 1, maxLength 100
           - name: audienceProviderData | type: object | description: audience provider data is needed in order to list participants of each provider  
        - name: locationIds | type: array<string> | description: Location GUIDs used to filter for participants relevant to these locations.  | validation: maxItems 30, format GUID
 Return type: PROMISE<CountParticipantsResponse>
  - name: audienceParticipantCount | type: array<ParticipantCount> | description: Participant count broken down by audience provider, based on the audience configuration given in the request.  If a provider doesn't implement `countParticipants`, its `count` is `1` instead of an exact number.  | validation: maxItems 20
     - name: audienceProviderId | type: string | description: GUID of the provider, in the format `{appId}_{key}`.  | validation: minLength 1, maxLength 100
     - name: count | type: integer | description: Total count of participants for the provider.  
     - name: type | type: ParticipantType | description: Type of the participant.  
         - enum: WIX_USER, CONTACT, ANONYMOUS

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_PROVIDER_ID | Description: The audience's `audienceProviderId` isn't in the expected `{appId}_{key}` format.


```

### Examples

### Estimate how many contacts are labeled VIP Customer
Retrieves the number of participants in the same audience of contacts labeled `custom.vip-customer`, without resolving the participants themselves.

```javascript
import { audiences } from "@wix/audiences";

async function countParticipants() {
  const response = await audiences.countParticipants({
    audiences: [
      {
        audienceProviderId: "74bff718-5977-47f2-9e5f-a9fd0047fd1f_labels",
        audienceProviderData: {
          labelIds: ["custom.vip-customer"],
        },
      },
    ],
  });
}

/* Promise resolves to:
 * {
 *   "audienceParticipantCount": [
 *     {
 *       "audienceProviderId": "74bff718-5977-47f2-9e5f-a9fd0047fd1f_labels",
 *       "count": 1,
 *       "type": "CONTACT"
 *     }
 *   ]
 * }
 */

```

### countParticipants (self-hosted)
Self-hosted 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 { audiences } from '@wix/audiences';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

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


async function countParticipants(options) {
  const response = await myWixClient.audiences.countParticipants(options);
};
```

---