> 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

# 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.  | validation: format GUID
   param name: displayNamespace | type: displayNamespace | description: Optional display name for the namespace that appears on the target site.  | validation: maxLength 100
   param name: namespace | type: namespace | description: Namespace to connect collection with on the target site. Must be unique in the site. | required: true | validation: minLength 1, maxLength 100
 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.  | validation: maxLength 255
     - name: sourceSiteId | type: string | description: GUID of the source site that owns the collection and created the policy.  | validation: format GUID
     - name: targetDataCollectionId | type: string | description: GUID of the shared collection on the target site. The GUID includes the namespace. For example, `"namespace/collectionName"`.  | validation: maxLength 255
     - name: targetSiteId | type: string | description: GUID of the target site that the collection is shared with.  | validation: format GUID
     - name: targetDisplayNamespace | type: string | description: Optional display name for the namespace that appears on the target site.  | validation: maxLength 100
     - name: dataSharingPolicyId | type: string | description: GUID of the data sharing policy that controls this connection.  | validation: format GUID
     - name: createdDate | type: string | description: Date and time the connection was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date and time the connection was last updated.  | read-only: true | validation: format date-time

 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: <AUTH>' \
    -d '{
      "by": { "dataSharingPolicyId": "f6d058c0-6d5a-4ca5-b4a6-24933fce9175" },
      "namespace": "shared",
      "displayNamespace": "Shared"
    }'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.data.sharing.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 | validation: minLength 1, maxLength 100
   param name: options | type: ConnectToSharedCollectionOptions  none  
        - name: displayNamespace | type: string | description: Optional display name for the namespace that appears on the target site.  | validation: maxLength 100
        - name: dataSharingPolicyId | type: string | description: Data sharing policy GUID to connect with.  | validation: format GUID
 Return type: PROMISE<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.  | validation: maxLength 255
     - name: sourceSiteId | type: string | description: GUID of the source site that owns the collection and created the policy.  | validation: format GUID
     - name: targetDataCollectionId | type: string | description: GUID of the shared collection on the target site. The GUID includes the namespace. For example, `"namespace/collectionName"`.  | validation: maxLength 255
     - name: targetSiteId | type: string | description: GUID of the target site that the collection is shared with.  | validation: format GUID
     - name: targetDisplayNamespace | type: string | description: Optional display name for the namespace that appears on the target site.  | validation: maxLength 100
     - name: dataSharingPolicyId | type: string | description: GUID of the data sharing policy that controls this connection.  | validation: format GUID
     - name: _createdDate | type: Date | description: Date and time the connection was created.  | read-only: true 
     - name: _updatedDate | type: Date | description: Date and time the connection was last updated.  | read-only: true 

 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-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 { 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);
};
```

---