> 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

# BulkInsertDataItemReferences

# Package: cms

# Namespace: DataItemService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/bulk-insert-data-item-references.md

## Permission Scopes:
Write Data Items: SCOPE.DC-DATA.WRITE

## Introduction

Inserts one or more references in the specified fields of items in a collection.


This method adds one or more references to a collection.
Each new reference in the `dataItemReferences` field specifies a referring item's ID, the field in which to insert the reference, and the ID of the referenced item.

---

## REST API

### Schema

```
 Method: bulkInsertDataItemReferences
 Description: Inserts one or more references in the specified fields of items in a collection.   This method adds one or more references to a collection. Each new reference in the `dataItemReferences` field specifies a referring item's GUID, the field in which to insert the reference, and the GUID of the referenced item.
 URL: https://www.wixapis.com/wix-data/v2/bulk/items/insert-references
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  dataCollectionId, dataItemReferences, dataItemReferences.referringItemFieldName, dataItemReferences.referringItemId, dataItemReferences.referencedItemId
 Method parameters: 
   param name: dataCollectionId | type: dataCollectionId | description: GUID of the collection containing the referring items. | required: true | validation: maxLength 256
   param name: dataItemReferences | type: array<dataItemReferences> | description: References to insert. | required: true | validation: maxItems 1000
              - name: referringItemFieldName | type: string | description: Referring item field containing the references to the referenced items. | required: true | validation: maxLength 1000
              - name: referringItemId | type: string | description: GUID of the referring item. | required: true | validation: maxLength 128
              - name: referencedItemId | type: string | description: GUID of the referenced item. | required: true | validation: maxLength 128
   param name: returnEntity | type: returnEntity | description: Whether to return the inserted data item references. When `true`, the `results` objects contain a `dataItemReference` field.  Default: `false`  
 Return type: BulkInsertDataItemReferencesResponse
  - name: results | type: array<BulkDataItemReferenceResult> | description: Information about the inserted references.  
     - name: action | type: BulkActionType | description: The action attempted for the reference.  
         - enum: UNKNOWN_ACTION_TYPE, INSERT, UPDATE, DELETE, PATCH
     - name: referenceMetadata | type: ItemMetadata | description: Metadata related to the reference for which the action was attempted.  
        - 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: dataItemReference | type: DataItemReference | description: The reference for which the action was attempted. Only returned if `returnEntity` is `true` in the request and the action is successful.  
        - name: referringItemFieldName | type: string | description: Referring item field containing the references to the referenced items.  | validation: maxLength 1000
        - name: referringItemId | type: string | description: GUID of the referring item.  | validation: maxLength 128
        - name: referencedItemId | type: string | description: GUID of the referenced item.  | validation: maxLength 128
  - name: bulkActionMetadata | type: BulkActionMetadata | description: Bulk action metadata.  
     - name: totalSuccesses | type: integer | description: Number of items successfully processed.  
     - name: totalFailures | type: integer | description: Number of items that couldn't be processed.  


```

### Examples

### Bulk insert references and return inserted result
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v2/bulk/items/insert-references' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
    "dataCollectionId": "albums",
    "dataItemReferences": [
        {
            "referringItemFieldName": "songs",
            "referringItemId": "37de298e-026d-4b2e-b87f-fbec11d53105",
            "referencedItemId": "aafeaaf4-6192-4cc2-a79b-97ce0f1b3646"
        },
        {
            "referringItemFieldName": "songs",
            "referringItemId": "37de298e-026d-4b2e-b87f-fbec11d53105",
            "referencedItemId": "e7fe3827-5102-470a-a10a-b6221dd0b4a9"
        }
    ],
    "returnEntity": true
}'
```

### Bulk insert references
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v2/bulk/items/insert-references' \
-H 'Content-Type: application/json' \
-H 'Authorization: <AUTH>' \
-d '{
    "dataCollectionId": "albums",
    "dataItemReferences": [
        {
            "referringItemFieldName": "songs",
            "referringItemId": "37de298e-026d-4b2e-b87f-fbec11d53105",
            "referencedItemId": "aafeaaf4-6192-4cc2-a79b-97ce0f1b3646"
        },
        {
            "referringItemFieldName": "songs",
            "referringItemId": "37de298e-026d-4b2e-b87f-fbec11d53105",
            "referencedItemId": "e7fe3827-5102-470a-a10a-b6221dd0b4a9"
        }
    ]
}'
```

---