> 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

# BulkGetSharedCollectionStats

# Package: collectionManagement

# Namespace: DataCollectionSharingService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-sharing/bulk-get-shared-collection-stats.md

## Permission Scopes:
Manage Data Collection Sharing: SCOPE.DATA.MANAGE_COLLECTION_SHARING

## Introduction

Retrieves sharing statistics for data collections shared out from the current site.

For each source data collection, returns the number of distinct target sites the collection is
currently shared with. Use this when you need a per-collection sharing summary
(for example, a "Shared with N sites" indicator) without retrieving the full list of sharing connections.

You can look up stats for up to 100 collections per call by specifying `sourceDataCollectionIds`.
Leave `sourceDataCollectionIds` empty to return stats for every source data collection on the current site
that has at least one active sharing connection.

When you specify `sourceDataCollectionIds`, the response contains one result per distinct provided ID.
A result has `itemMetadata.success = true` and `stats` populated when the collection has at least
one active sharing connection. Otherwise, `itemMetadata.success = false` with
`itemMetadata.error.code = "NOT_FOUND"`.

To retrieve the full list of sharing connections (including target site and collection IDs), call
[List Shared Data Collections](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-sharing-policy-v1/list-shared-data-collections.md)
with `sharedWithCurrentSite` set to `false`.

> **Note:** `connectedSitesCount` counts distinct target sites. If the same target site connects
> through multiple policies, it is counted once.

---

## REST API

### Schema

```
 Method: bulkGetSharedCollectionStats
 Description: Retrieves sharing statistics for data collections shared out from the current site.  For each source data collection, returns the number of distinct target sites the collection is currently shared with. Use this when you need a per-collection sharing summary (for example, a "Shared with N sites" indicator) without retrieving the full list of sharing connections.  You can look up stats for up to 100 collections per call by specifying `sourceDataCollectionIds`. Leave `sourceDataCollectionIds` empty to return stats for every source data collection on the current site that has at least one active sharing connection.  When you specify `sourceDataCollectionIds`, the response contains one result per distinct provided GUID. A result has `itemMetadata.success = true` and `stats` populated when the collection has at least one active sharing connection. Otherwise, `itemMetadata.success = false` with `itemMetadata.error.code = "NOT_FOUND"`.  To retrieve the full list of sharing connections (including target site and collection GUIDs), call [List Shared Data Collections](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-sharing-policy-v1/list-shared-data-collections.md) with `sharedWithCurrentSite` set to `false`.  > **Note:** `connectedSitesCount` counts distinct target sites. If the same target site connects > through multiple policies, it is counted once.
 URL: https://www.wixapis.com/data/v1/data-collection-sharing/bulk-get-stats
 Method: POST
 Method parameters:
   param name: sourceDataCollectionIds | type: array<sourceDataCollectionIds> | description: Optional. Source data collection GUIDs to look up.  Maximum: 100 GUIDs per request.  If empty, returns one successful result per source data collection on the current site that has at least one active sharing connection. If non-empty, returns one result per distinct provided GUID. Duplicate GUIDs are deduplicated; each GUID's `itemMetadata.originalIndex` reflects its first position in the request array. A result has `itemMetadata.success = true` with `stats` populated when the collection has at least one active sharing connection; otherwise `itemMetadata.success = false` with `itemMetadata.error.code = "NOT_FOUND"`.  | validation: maxItems 100, maxLength 255
 Return type: BulkGetSharedCollectionStatsResponse
  - name: results | type: array<BulkSharedCollectionStatsResult> | description: Per-collection sharing stats results.  When `sourceDataCollectionIds` is empty, contains one successful result per source data collection on the current site that has at least one active sharing connection. When `sourceDataCollectionIds` is non-empty, contains one result per distinct provided GUID.  
     - name: itemMetadata | type: ItemMetadata | description: Per-item metadata: success flag, original request index, and error details when the lookup failed.  `itemMetadata.id` is set to the source data collection GUID. When `itemMetadata.success` is `false`, `itemMetadata.error.code` is `"NOT_FOUND"`.  
        - name: id | type: string | description: Item GUID. Does not appear if the item GUID is missing. For example, when item creation fails.  | validation: maxLength 128
        - name: originalIndex | type: integer | description: Original index of the item in the array specified in the request. Use this to match items in the request with those in the response.  
        - name: success | type: boolean | description: Whether the requested action was successful. When `false`, the `error` field is populated.  
        - name: error | type: ApplicationError | description: In case of failure, the error details.  
           - name: code | type: string | description: Error code.  
           - name: description | type: string | description: Description of the error.  
           - name: data | type: object | description: Data related to the error.  
     - name: stats | type: SharedCollectionStats | description: Sharing stats for the collection. Populated only when `itemMetadata.success` is `true`.  
        - name: sourceDataCollectionId | type: string | description: Source data collection GUID on the current site.  | validation: maxLength 255
        - name: connectedSitesCount | type: integer | description: Number of distinct target sites the collection is currently shared with.  If the same target site connects through multiple sharing policies, it is counted once.  
  - name: bulkActionMetadata | type: BulkActionMetadata | description: Aggregate success and failure counts across `results`.  
     - name: totalSuccesses | type: integer | description: Number of items successfully processed.  
     - name: totalFailures | type: integer | description: Number of items that couldn't be processed.  


```

### Examples

### Handle a collection with no active sharing connections
```curl
curl -X GET \
  'https://wixapis.com/wix-data/v1/data-collection-sharing/bulk-get-stats?sourceDataCollectionIds=Articles&sourceDataCollectionIds=ArchivedContent' \
  -H 'Authorization: <AUTH>'
```

### Get sharing stats for all shared-out collections
```curl
curl -X POST \
  'https://wixapis.com/wix-data/v1/data-collection-sharing/bulk-get-stats' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  -d '{}'
```

### Get sharing stats for specific collections
```curl
curl -X POST \
  'https://wixapis.com/wix-data/v1/data-collection-sharing/bulk-get-stats' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: <AUTH>' \
  -d '{
    "sourceDataCollectionIds": [
      "Articles",
      "Products"
    ]
  }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.data.sharing.bulkGetSharedCollectionStats(options)
 Description: Retrieves sharing statistics for data collections shared out from the current site.  For each source data collection, returns the number of distinct target sites the collection is currently shared with. Use this when you need a per-collection sharing summary (for example, a "Shared with N sites" indicator) without retrieving the full list of sharing connections.  You can look up stats for up to 100 collections per call by specifying `sourceDataCollectionIds`. Leave `sourceDataCollectionIds` empty to return stats for every source data collection on the current site that has at least one active sharing connection.  When you specify `sourceDataCollectionIds`, the response contains one result per distinct provided GUID. A result has `itemMetadata.success = true` and `stats` populated when the collection has at least one active sharing connection. Otherwise, `itemMetadata.success = false` with `itemMetadata.error.code = "NOT_FOUND"`.  To retrieve the full list of sharing connections (including target site and collection GUIDs), call [List Shared Data Collections](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-sharing-policy-v1/list-shared-data-collections.md) with `sharedWithCurrentSite` set to `false`.  > **Note:** `connectedSitesCount` counts distinct target sites. If the same target site connects > through multiple policies, it is counted once.
 Method parameters:
   param name: options | type: BulkGetSharedCollectionStatsOptions  none  
        - name: sourceDataCollectionIds | type: array<string> | description: Optional. Source data collection GUIDs to look up.  Maximum: 100 GUIDs per request.  If empty, returns one successful result per source data collection on the current site that has at least one active sharing connection. If non-empty, returns one result per distinct provided GUID. Duplicate GUIDs are deduplicated; each GUID's `itemMetadata.originalIndex` reflects its first position in the request array. A result has `itemMetadata.success = true` with `stats` populated when the collection has at least one active sharing connection; otherwise `itemMetadata.success = false` with `itemMetadata.error.code = "NOT_FOUND"`.  | validation: maxItems 100, maxLength 255
 Return type: PROMISE<BulkGetSharedCollectionStatsResponse>
  - name: results | type: array<BulkSharedCollectionStatsResult> | description: Per-collection sharing stats results.  When `sourceDataCollectionIds` is empty, contains one successful result per source data collection on the current site that has at least one active sharing connection. When `sourceDataCollectionIds` is non-empty, contains one result per distinct provided GUID.  
     - name: itemMetadata | type: ItemMetadata | description: Per-item metadata: success flag, original request index, and error details when the lookup failed.  `itemMetadata.id` is set to the source data collection GUID. When `itemMetadata.success` is `false`, `itemMetadata.error.code` is `"NOT_FOUND"`.  
        - name: _id | type: string | description: Item GUID. Does not appear if the item GUID is missing. For example, when item creation fails.  | validation: maxLength 128
        - name: originalIndex | type: integer | description: Original index of the item in the array specified in the request. Use this to match items in the request with those in the response.  
        - name: success | type: boolean | description: Whether the requested action was successful. When `false`, the `error` field is populated.  
        - name: error | type: ApplicationError | description: In case of failure, the error details.  
           - name: code | type: string | description: Error code.  
           - name: description | type: string | description: Description of the error.  
           - name: data | type: object | description: Data related to the error.  
     - name: stats | type: SharedCollectionStats | description: Sharing stats for the collection. Populated only when `itemMetadata.success` is `true`.  
        - name: sourceDataCollectionId | type: string | description: Source data collection GUID on the current site.  | validation: maxLength 255
        - name: connectedSitesCount | type: integer | description: Number of distinct target sites the collection is currently shared with.  If the same target site connects through multiple sharing policies, it is counted once.  
  - name: bulkActionMetadata | type: BulkActionMetadata | description: Aggregate success and failure counts across `results`.  
     - name: totalSuccesses | type: integer | description: Number of items successfully processed.  
     - name: totalFailures | type: integer | description: Number of items that couldn't be processed.  


```

### Examples

### bulkGetSharedCollectionStats
```javascript
import { sharing } from '@wix/data';

async function bulkGetSharedCollectionStats(options) {
  const response = await sharing.bulkGetSharedCollectionStats(options);
};
```

### bulkGetSharedCollectionStats (with elevated permissions)
```javascript
import { sharing } from '@wix/data';
import { auth } from '@wix/essentials';

async function myBulkGetSharedCollectionStatsMethod(options) {
  const elevatedBulkGetSharedCollectionStats = auth.elevate(sharing.bulkGetSharedCollectionStats);
  const response = await elevatedBulkGetSharedCollectionStats(options);
}
```

### bulkGetSharedCollectionStats (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 { sharing } from '@wix/data';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

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


async function bulkGetSharedCollectionStats(options) {
  const response = await myWixClient.sharing.bulkGetSharedCollectionStats(options);
};
```

---