> 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 # CreateDataSharingPolicy # Package: collectionManagement # Namespace: DataCollectionSharingService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-sharing/create-data-sharing-policy.md ## Permission Scopes: Manage Data Collection Sharing: SCOPE.DATA.MANAGE_COLLECTION_SHARING ## Introduction Creates a data sharing policy for the specified collection. You can optionally filter which items in the collection can be shared. If no filters are specified, all items in the collection are shared. You can create multiple policies for the same collection with different filters. You can find which fields can be filtered for each collection by calling [Get Data Collection](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-collections/get-data-collection.md). The supported filters are returned in the response under `collections.fields.capabilities.queryOperators`.
__Important:__ Only collections created in the CMS or with the [Data Collections API](https://dev.wix.com/docs/api-reference/business-solutions/cms/introduction.md) can be shared. External collections and Wix App collections can't be shared.
--- ## REST API ### Schema ``` Method: createDataSharingPolicy Description: Creates a data sharing policy for the specified collection. You can optionally filter which items in the collection can be shared. If no filters are specified, all items in the collection are shared. You can create multiple policies for the same collection with different filters. You can find which fields can be filtered for each collection by calling [Get Data Collection](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-collections/get-data-collection.md). The supported filters are returned in the response under `collections.fields.capabilities.queryOperators`.
__Important:__ Only collections created in the CMS or with the [Data Collections API](https://dev.wix.com/docs/api-reference/business-solutions/cms/introduction.md) can be shared. External collections and Wix App collections can't be shared.
URL: https://www.wixapis.com/data/v1/data-collection-sharing/policies Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: dataSharingPolicy.dataCollectionId Method parameters: param name: dataSharingPolicy | type: DataSharingPolicy | description: A data sharing policy defines how a data collection is shared between sites in the same Wix account. The policy specifies which collection to share, optional filtering rules to control which items are accessible, and serves as the access credential for other sites to connect to the shared collection. Multiple policies can be created for the same collection with different filtering rules or access patterns. - name: dataCollectionId | type: string | description: GUID of the data collection to share. | required: true - name: dataItemsFilter | type: object | description: Filter to restrict which items from the collection are shared. Use [API Query Language syntax](https://dev.wix.com/api/rest/getting-started/api-query-language) to define filtering rules. If not specified, all items in the collection are shared. Return type: CreateDataSharingPolicyResponse - name: dataSharingPolicy | type: DataSharingPolicy | description: Created data sharing policy. - name: id | type: string | description: Data sharing policy GUID. - name: dataCollectionId | type: string | description: GUID of the data collection to share. - name: dataItemsFilter | type: object | description: Filter to restrict which items from the collection are shared. Use [API Query Language syntax](https://dev.wix.com/api/rest/getting-started/api-query-language) to define filtering rules. If not specified, all items in the collection are shared. - name: createdDate | type: string | description: Date and time the data sharing policy was created. - name: updatedDate | type: string | description: Date and time the data sharing policy was last updated. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: WDE0107 | Description: Collection type can't be shared. Verify the collection isn't an external collection or a Wix App collection. HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: WDE0025 | Description: Collection not found. Verify the collection GUID is correct and that the collection exists. ``` ### Examples ### Create data sharing policy ```curl curl -X POST https://wixapis.com/wix-data/v1/data-collection-sharing/policies \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Authorization: ' -d '{ "dataSharingPolicy": { "dataCollectionId": "myCollection", "dataItemsFilter": null } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.collectionManagement.DataCollectionSharingService.createDataSharingPolicy(options) Description: Creates a data sharing policy for the specified collection. You can optionally filter which items in the collection can be shared. If no filters are specified, all items in the collection are shared. You can create multiple policies for the same collection with different filters. You can find which fields can be filtered for each collection by calling [Get Data Collection](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-collections/get-data-collection.md). The supported filters are returned in the response under `collections.fields.capabilities.queryOperators`.
__Important:__ Only collections created in the CMS or with the [Data Collections API](https://dev.wix.com/docs/api-reference/business-solutions/cms/introduction.md) can be shared. External collections and Wix App collections can't be shared.
# Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: options.dataSharingPolicy.dataCollectionId Method parameters: param name: options | type: CreateDataSharingPolicyOptions none - name: dataSharingPolicy | type: DataSharingPolicy | description: Data sharing policy to create. - name: dataCollectionId | type: string | description: GUID of the data collection to share. | required: true - name: dataItemsFilter | type: object | description: Filter to restrict which items from the collection are shared. Use [API Query Language syntax](https://dev.wix.com/api/rest/getting-started/api-query-language) to define filtering rules. If not specified, all items in the collection are shared. Return type: PROMISE - name: _id | type: string | description: Data sharing policy GUID. - name: dataCollectionId | type: string | description: GUID of the data collection to share. - name: dataItemsFilter | type: object | description: Filter to restrict which items from the collection are shared. Use [API Query Language syntax](https://dev.wix.com/api/rest/getting-started/api-query-language) to define filtering rules. If not specified, all items in the collection are shared. - name: _createdDate | type: Date | description: Date and time the data sharing policy was created. - name: _updatedDate | type: Date | description: Date and time the data sharing policy was last updated. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: WDE0107 | Description: Collection type can't be shared. Verify the collection isn't an external collection or a Wix App collection. HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: WDE0025 | Description: Collection not found. Verify the collection GUID is correct and that the collection exists. ``` ### Examples ### createDataSharingPolicy ```javascript import { sharing } from '@wix/data'; async function createDataSharingPolicy(options) { const response = await sharing.createDataSharingPolicy(options); }; ``` ### createDataSharingPolicy (with elevated permissions) ```javascript import { sharing } from '@wix/data'; import { auth } from '@wix/essentials'; async function myCreateDataSharingPolicyMethod(options) { const elevatedCreateDataSharingPolicy = auth.elevate(sharing.createDataSharingPolicy); const response = await elevatedCreateDataSharingPolicy(options); } ``` ### createDataSharingPolicy (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 createDataSharingPolicy(options) { const response = await myWixClient.sharing.createDataSharingPolicy(options); }; ``` ---