> 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

# Method name: createDataCollection(collection: DataCollection)

# Method package: wixDataV2

# Method menu location: wixDataV2 --> collections --> createDataCollection

# Method Link: https://dev.wix.com/docs/velo/apis/wix-data-v2/collections/create-data-collection.md

# Method Description:

Creates a new data collection.

The request body must include an ID, details for at least 1 field, and a permissions object. If any of these are missing, the collection isn't created.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Create a data collection that only authorized users can edit (dashboard page code)

```javascript
import { collections } from "wix-data.v2";

/* Sample collection object: 
 *
 * const newCollection = {
 *   _id: "myMusicCollection",
 *   permissions: {
 *     read: "ANYONE",
 *     insert: "SITE_MEMBER_AUTHOR",
 *     update: "SITE_MEMBER_AUTHOR",
 *     remove: "SITE_MEMBER_AUTHOR"
 *   },
 *   fields: [
 *     {
 *       key: "artist",
 *       displayName: "Artist Name",
 *       description: "The artist's name",
 *       type: "TEXT"
 *     },
 *     {
 *       key: "songTitle",
 *       displayName: "Song Title",
 *       description: "The song's full title",
 *       type: "TEXT" 
 *     },
 *     {
 *       key: "uploadedBy",
 *       displayName: "Uploaded By",
 *       description: "The person who uploaded the song",
 *       type: "TEXT",
 *       plugins: [
 *         {
 *           type: "CMS",
 *           cmsOptions: {
 *             internal: true
 *           }
 *         }
 *       ]
 *     }
 *   ]
 * }; 
 */

export async function myCreateDataCollectionFunction(newCollection) {
  try {
    const createDataCollectionResponse = await collections.createDataCollection(newCollection);
    return createDataCollectionResponse;
  } catch (error) {
    console.error(error);
    // Handle the error
  } 
}

/* Returns a promise that resolves to the created collection:
 * 
 * {
 *   "_createdDate": "2024-01-04T08:57:43.872Z",
 *   "_id": "myThirdMusicCollection",
 *   "_updatedDate": "2024-01-04T08:57:43.872Z",
 *   "capabilities": {
 *     "collectionOperations": [
 *       "REMOVE",
 *       "UPDATE"
 *     ],
 *     "dataOperations": [
 *       "AGGREGATE",
 *       "BULK_INSERT",
 *       "BULK_REMOVE",
 *       "BULK_SAVE",
 *       "BULK_UPDATE",
 *       "COUNT",
 *       "DISTINCT",
 *       "FIND",
 *       "GET",
 *       "INSERT",
 *       "INSERT_REFERENCE",
 *       "IS_REFERENCED",
 *       "QUERY_REFERENCED",
 *       "REPLACE_REFERENCES",
 *       "REMOVE",
 *       "REMOVE_REFERENCE",
 *       "SAVE",
 *       "UPDATE"
 *     ],
 *     "indexLimits": {
 *       "regular": 3,
 *       "total": 4,
 *       "unique": 1
 *     }
 *   },
 *   "collectionType": "NATIVE",
 *   "displayField": "artist",
 *   "displayName": "myMusicCollection",
 *   "fields": [
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "description": "The artist's name",
 *       "displayName": "Artist Name",
 *       "encrypted": false,
 *       "key": "artist",
 *       "plugins": [],
 *       "systemField": false,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "description": "The song's full title",
 *       "displayName": "Song Title",
 *       "encrypted": false,
 *       "key": "songTitle",
 *       "plugins": [],
 *       "systemField": false,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "description": "The person who uploaded the song",
 *       "displayName": "Uploaded By",
 *       "encrypted": false,
 *       "key": "uploadedBy",
 *       "plugins": [
 *         {
 *           "cmsOptions": {
 *             "internal": true
 *           },
 *           "type": "CMS"
 *         }
 *       ],
 *       "systemField": false,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "ID",
 *       "encrypted": false,
 *       "key": "_id",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "Created Date",
 *       "encrypted": false,
 *       "key": "_createdDate",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "DATETIME"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "Updated Date",
 *       "encrypted": false,
 *       "key": "_updatedDate",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "DATETIME"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "Owner",
 *       "encrypted": false,
 *       "key": "_owner",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "TEXT"
 *     }
 *   ],
 *   "pagingModes": [
 *     "OFFSET"
 *   ],
 *   "permissions": {
 *     "insert": "SITE_MEMBER_AUTHOR",
 *     "read": "ANYONE",
 *     "remove": "SITE_MEMBER_AUTHOR",
 *     "update": "SITE_MEMBER_AUTHOR"
 *   },
 *   "plugins": [],
 *   "revision": "1"
 * }
 */

```

## Create a data collection that only authorized users can edit (export from backend code)

```javascript
import { Permissions, webMethod } from "wix-web-module";
import { collections } from "wix-data.v2";

/* Sample collection object: 
 *
 * const newCollection = {
 *   _id: "myMusicCollection",
 *   permissions: {
 *     read: "ANYONE",
 *     insert: "SITE_MEMBER_AUTHOR",
 *     update: "SITE_MEMBER_AUTHOR",
 *     remove: "SITE_MEMBER_AUTHOR"
 *   },
 *   fields: [
 *     {
 *       key: "artist",
 *       displayName: "Artist Name",
 *       description: "The artist's name",
 *       type: "TEXT"
 *     },
 *     {
 *       key: "songTitle",
 *       displayName: "Song Title",
 *       description: "The song's full title",
 *       type: "TEXT" 
 *     },
 *     {
 *       key: "uploadedBy",
 *       displayName: "Uploaded By",
 *       description: "The person who uploaded the song",
 *       type: "TEXT",
 *       plugins: [
 *         {
 *           type: "CMS",
 *           cmsOptions: {
 *             internal: true
 *           }
 *         }
 *       ]
 *     }
 *   ]
 * }; 
 */

export const myCreateDataCollectionFunction = webMethod(Permissions.Anyone, async (newCollection) => {
  try {
    const createDataCollectionResponse = await collections.createDataCollection(newCollection);
    return createDataCollectionResponse;
  } catch (error) {
    console.error(error);
    // Handle the error
  } 
});


/* Returns a promise that resolves to the created collection:
 * 
 * {
 *   "_createdDate": "2024-01-04T08:57:43.872Z",
 *   "_id": "myThirdMusicCollection",
 *   "_updatedDate": "2024-01-04T08:57:43.872Z",
 *   "capabilities": {
 *     "collectionOperations": [
 *       "REMOVE",
 *       "UPDATE"
 *     ],
 *     "dataOperations": [
 *       "AGGREGATE",
 *       "BULK_INSERT",
 *       "BULK_REMOVE",
 *       "BULK_SAVE",
 *       "BULK_UPDATE",
 *       "COUNT",
 *       "DISTINCT",
 *       "FIND",
 *       "GET",
 *       "INSERT",
 *       "INSERT_REFERENCE",
 *       "IS_REFERENCED",
 *       "QUERY_REFERENCED",
 *       "REPLACE_REFERENCES",
 *       "REMOVE",
 *       "REMOVE_REFERENCE",
 *       "SAVE",
 *       "UPDATE"
 *     ],
 *     "indexLimits": {
 *       "regular": 3,
 *       "total": 4,
 *       "unique": 1
 *     }
 *   },
 *   "collectionType": "NATIVE",
 *   "displayField": "artist",
 *   "displayName": "myMusicCollection",
 *   "fields": [
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "description": "The artist's name",
 *       "displayName": "Artist Name",
 *       "encrypted": false,
 *       "key": "artist",
 *       "plugins": [],
 *       "systemField": false,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "description": "The song's full title",
 *       "displayName": "Song Title",
 *       "encrypted": false,
 *       "key": "songTitle",
 *       "plugins": [],
 *       "systemField": false,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "description": "The person who uploaded the song",
 *       "displayName": "Uploaded By",
 *       "encrypted": false,
 *       "key": "uploadedBy",
 *       "plugins": [
 *         {
 *           "cmsOptions": {
 *             "internal": true
 *           },
 *           "type": "CMS"
 *         }
 *       ],
 *       "systemField": false,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "ID",
 *       "encrypted": false,
 *       "key": "_id",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "TEXT"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "Created Date",
 *       "encrypted": false,
 *       "key": "_createdDate",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "DATETIME"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "Updated Date",
 *       "encrypted": false,
 *       "key": "_updatedDate",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "DATETIME"
 *     },
 *     {
 *       "capabilities": {
 *         "queryOperators": [
 *           "CONTAINS",
 *           "ENDS_WITH",
 *           "EQ",
 *           "EXISTS",
 *           "GTE",
 *           "GT",
 *           "HAS_ALL",
 *           "HAS_SOME",
 *           "LT",
 *           "LTE",
 *           "NE",
 *           "STARTS_WITH",
 *           "URLIZED"
 *         ],
 *         "sortable": true
 *       },
 *       "displayName": "Owner",
 *       "encrypted": false,
 *       "key": "_owner",
 *       "plugins": [],
 *       "systemField": true,
 *       "type": "TEXT"
 *     }
 *   ],
 *   "pagingModes": [
 *     "OFFSET"
 *   ],
 *   "permissions": {
 *     "insert": "SITE_MEMBER_AUTHOR",
 *     "read": "ANYONE",
 *     "remove": "SITE_MEMBER_AUTHOR",
 *     "update": "SITE_MEMBER_AUTHOR"
 *   },
 *   "plugins": [],
 *   "revision": "1"
 * }
 */

```

## Create a permissions-protected collection with dynamic URLs 

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { collections } from 'wix-data.v2';

/* Sample collection object:
 * Includes a plugin that generates dynamic pages for each item in the collection.
 *
 * const newCollection = {
 *   _id: "shirts",
 *   displayName: "Shirts",
 *   displayField: "shirts",
 *   permissions: {
 *     read: "ANYONE",
 *     insert: "SITE_MEMBER_AUTHOR",
 *     update: "SITE_MEMBER_AUTHOR",
 *     remove: "SITE_MEMBER_AUTHOR"
 *   },
 *   fields: 
 *   [
 *     {
 *       key: "name",
 *       displayName: "Item Name",
 *       description: "Name of item, required",
 *       required: true
 *     },
 *     {
 *       key: "price",
 *       displayName: "Item Price",
 *       description: "Price of item, required",
 *       required: true
 *     },
 *     {
 *       key: "description",
 *       displayName: "Item Description",
 *       description: "Item description, not required",
 *       required: false
 *     },
 *   ],
 *   plugins: 
 *   [
 *    {
 *      type: "URLIZED",
 *      urlizedOptions: {
 *        format: "ORIGINAL"
 *      }
 *    }
 *   ]
 * }; 
 */ 

export const myCreateDataCollectionFunctionAdvanced = webMethod(Permissions.Anyone, async (newCollection) => {
    try {
        const createDataCollectionResponse = await collections.createDataCollection(newCollection);
        return createDataCollectionResponse;
    } catch (error) {
        console.error(error);
        // Handle the error
    } 
});

/* Returns a promise that resolves to the created collection:
 * {
 *   "_id": "shirts",
 *   "collectionType": "NATIVE",
 *   "displayName": "Shirts",
 *   "displayField": "shirts",
 *   "capabilities": {
 *     "dataOperations": [
 *       "IS_REFERENCED",
 *       "INSERT",
 *       "SAVE",
 *       "BULK_INSERT",
 *       "BULK_UPDATE",
 *       "UPDATE",
 *       "TRUNCATE",
 *       "REMOVE",
 *       "REMOVE_REFERENCE",
 *       "COUNT",
 *       "FIND",
 *       "REPLACE_REFERENCES",
 *       "BULK_REMOVE",
 *       "INSERT_REFERENCE",
 *       "GET",
 *       "BULK_SAVE",
 *       "QUERY_REFERENCED",
 *       "DISTINCT",
 *       "AGGREGATE"
 *     ],
 *     "collectionOperations": [
 *       "UPDATE",
 *       "REMOVE"
 *     ],
 *     "indexLimits": {
 *       "regular": 3,
 *       "unique": 1,
 *       "total": 4
 *     }
 *   },
 *   "fields": [
 *     {
 *       "key": "name",
 *       "displayName": "Item Name",
 *       "type": "TEXT",
 *       "systemField": false,
 *       "capabilities": {
 *         "sortable": true,
 *         "queryOperators": [
 *           "EQ",
 *           "LT",
 *           "GT",
 *           "NE",
 *           "LTE",
 *           "GTE",
 *           "STARTS_WITH",
 *           "ENDS_WITH",
 *           "CONTAINS",
 *           "HAS_SOME",
 *           "HAS_ALL",
 *           "EXISTS",
 *           "URLIZED"
 *         ]
 *       },
 *       "encrypted": false,
 *       "description": "Name of item, required",
 *       "required": true
 *     },
 *     // Additional system fields ... 
 *   ],
 *   "permissions": {
 *     "insert": "SITE_MEMBER_AUTHOR",
 *     "update": "SITE_MEMBER_AUTHOR",
 *     "remove": "SITE_MEMBER_AUTHOR",
 *     "read": "ANYONE"
 *   },
 *   "revision": "1",
 *   "plugins": 
 *   [
 *     {
 *       "type": "URLIZED",
 *       "urlizedOptions": {
 *         "format": "ORIGINAL"
 *       }
 *     }
 *   ],
 *   "pagingModes": 
 *   [
 *     "OFFSET"
 *   ],
 *   "_createdDate": "2023-07-23T11:38:41.518Z",
 *   "_updatedDate": "2023-07-23T11:38:41.518Z"
 * };
 */  

```

---