> 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 # ConnectToSharedCollection # Package: collectionManagement # Namespace: DataCollectionSharingService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-sharing/connect-to-shared-collection.md ## Permission Scopes: Manage Data Collection Sharing: SCOPE.DATA.MANAGE_COLLECTION_SHARING ## Introduction Connects the current site to a shared data collection. When you call this method, the shared collection appears in the current site's CMS under the specified namespace. You can also access the shared collection by using the [Data Items APIs](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction.md). > **Note:** The `namespace` is an identifier that serves as part of the collection ID when querying collection data. Therefore, it must be unique in a site. --- ## REST API ### Schema ``` Method: connectToSharedCollection Description: Connects the current site to a shared data collection. When you call this method, the shared collection appears in the current site's CMS under the specified namespace. You can also access the shared collection by using the [Data Items APIs](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction.md). > **Note:** The `namespace` is an identifier that serves as part of the collection GUID when querying collection data. Therefore, it must be unique in a site. URL: https://www.wixapis.com/data/v1/data-collection-sharing/connect-to-shared-collection Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: namespace Method parameters: param name: dataSharingPolicyId | type: dataSharingPolicyId | description: Data sharing policy GUID to connect with. param name: displayNamespace | type: displayNamespace | description: Optional display name for the namespace that appears on the target site. param name: namespace | type: namespace | description: Namespace to connect collection with on the target site. Must be unique in the site. | required: true Return type: ConnectToSharedCollectionResponse - name: connection | type: SharingConnection | description: Created connection to shared data collection. - name: sourceDataCollectionId | type: string | description: GUID of the data collection owned and shared by the source site. - name: sourceSiteId | type: string | description: GUID of the source site that owns the collection and created the policy. - name: targetDataCollectionId | type: string | description: GUID of the shared collection on the target site. The GUID includes the namespace. For example, `"namespace/collectionName"`. - name: targetSiteId | type: string | description: GUID of the target site that the collection is shared with. - name: targetDisplayNamespace | type: string | description: Optional display name for the namespace that appears on the target site. - name: dataSharingPolicyId | type: string | description: GUID of the data sharing policy that controls this connection. - name: createdDate | type: string | description: Date and time the connection was created. - name: updatedDate | type: string | description: Date and time the connection was last updated. Possible Errors: HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: WDE0144 | Description: Permissions denied. Must have `MANAGE DATA COLLECTION SHARING` permission. HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: WDE0154 | Description: Data sharing policy not found. Verify the policy GUID is correct. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: WDE0155 | Description: Collection already connected. This collection is already shared with the current site. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: WDE0102 | Description: Namespace already exists. Choose a namespace unique to the current site. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: WDE0104 | Description: Can't connect to your own collection. Source and target sites must be different. ``` ### Examples ### Connect to shared collection ```curl curl -X POST \ 'https://wixapis.com/wix-data/v1/data-collection-sharing/shared' \ -H 'Content-Type: application/json;charset=UTF-8' \ -H 'Authorization: ' \ -d '{ "by": { "dataSharingPolicyId": "f6d058c0-6d5a-4ca5-b4a6-24933fce9175" }, "namespace": "shared", "displayNamespace": "Shared" }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.collectionManagement.DataCollectionSharingService.connectToSharedCollection(namespace, options) Description: Connects the current site to a shared data collection. When you call this method, the shared collection appears in the current site's CMS under the specified namespace. You can also access the shared collection by using the [Data Items APIs](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction.md). > **Note:** The `namespace` is an identifier that serves as part of the collection GUID when querying collection data. Therefore, it must be unique in a site. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: namespace Method parameters: param name: namespace | type: string | description: Namespace to connect collection with on the target site. Must be unique in the site. | required: true param name: options | type: ConnectToSharedCollectionOptions none - name: displayNamespace | type: string | description: Optional display name for the namespace that appears on the target site. - name: dataSharingPolicyId | type: string | description: Data sharing policy GUID to connect with. Return type: PROMISE - name: connection | type: SharingConnection | description: Created connection to shared data collection. - name: sourceDataCollectionId | type: string | description: GUID of the data collection owned and shared by the source site. - name: sourceSiteId | type: string | description: GUID of the source site that owns the collection and created the policy. - name: targetDataCollectionId | type: string | description: GUID of the shared collection on the target site. The GUID includes the namespace. For example, `"namespace/collectionName"`. - name: targetSiteId | type: string | description: GUID of the target site that the collection is shared with. - name: targetDisplayNamespace | type: string | description: Optional display name for the namespace that appears on the target site. - name: dataSharingPolicyId | type: string | description: GUID of the data sharing policy that controls this connection. - name: _createdDate | type: Date | description: Date and time the connection was created. - name: _updatedDate | type: Date | description: Date and time the connection was last updated. Possible Errors: HTTP Code: 403 | Status Code: PERMISSION_DENIED | Application Code: WDE0144 | Description: Permissions denied. Must have `MANAGE DATA COLLECTION SHARING` permission. HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: WDE0154 | Description: Data sharing policy not found. Verify the policy GUID is correct. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: WDE0155 | Description: Collection already connected. This collection is already shared with the current site. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: WDE0102 | Description: Namespace already exists. Choose a namespace unique to the current site. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: WDE0104 | Description: Can't connect to your own collection. Source and target sites must be different. ``` ### Examples ### connectToSharedCollection ```javascript import { sharing } from '@wix/data'; async function connectToSharedCollection(namespace,options) { const response = await sharing.connectToSharedCollection(namespace,options); }; ``` ### connectToSharedCollection (with elevated permissions) ```javascript import { sharing } from '@wix/data'; import { auth } from '@wix/essentials'; async function myConnectToSharedCollectionMethod(namespace,options) { const elevatedConnectToSharedCollection = auth.elevate(sharing.connectToSharedCollection); const response = await elevatedConnectToSharedCollection(namespace,options); } ``` ### connectToSharedCollection (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 connectToSharedCollection(namespace,options) { const response = await myWixClient.sharing.connectToSharedCollection(namespace,options); }; ``` ---