> 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

# BulkPatchDataItems

# Package: cms

# Namespace: DataItemService

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

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

## Introduction

Patches one or more items in a collection.

Call this method when you need to apply partial changes to many items and want each item to keep fields that aren't mentioned in the request. This is also the right bulk surface for `fieldModifications` actions such as `SET_FIELD` and `INCREMENT_FIELD`: increments and decrements apply atomically on the server, so concurrent writers don't have to read the current value first or coordinate to avoid lost updates. For different behavior, you can call:

- [Bulk Update Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-update-data-items.md) to replace each item's full payload rather than patch part of it.
- [Save Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/save-data-item.md) per item for upsert behavior, meaning to create the item if its ID doesn't exist yet and update it if it does.

This method modifies the existing data of one or more items. Unlike [`Bulk Update Data Item`](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-update-data-items.md), only the fields specified in the request are modified. Data that isn't explicitly modified remains unchanged.

To patch items, specify the ID of the collection that contains them. For each item, specify its ID and the modifications you want to apply. If the item is found in the specified collection with the specified ID, that item is patched. If no such item is found, the response's `results` array contains a corresponding item whose `itemMetadata.error` property contains details about the error.

Learn more about [Wix Data error codes](https://dev.wix.com/docs/rest/business-solutions/cms/wix-data-error-codes.md).

> **Notes**:
> - When an item is patched, its `data._updatedDate` property is updated to the current date and time.
> - You can only patch items in [collections created by Wix users](https://support.wix.com/en/article/cms-formerly-content-manager-creating-a-collection). Items in [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code.md) cannot be patched.
> - Calling this method triggers the [`Data Item Updated`](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/data-item-updated.md) event for each patched item.

---

## REST API

### Schema

```
 Method: bulkPatchDataItems
 Description: Patches one or more items in a collection.  Call this method when you need to apply partial changes to many items and want each item to keep fields that aren't mentioned in the request. This is also the right bulk surface for `fieldModifications` actions such as `SET_FIELD` and `INCREMENT_FIELD`: increments and decrements apply atomically on the server, so concurrent writers don't have to read the current value first or coordinate to avoid lost updates. For different behavior, you can call:  - [Bulk Update Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-update-data-items.md) to replace each item's full payload rather than patch part of it. - [Save Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/save-data-item.md) per item for upsert behavior, meaning to create the item if its GUID doesn't exist yet and update it if it does.  This method modifies the existing data of one or more items. Unlike [`Bulk Update Data Item`](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-update-data-items.md), only the fields specified in the request are modified. Data that isn't explicitly modified remains unchanged.  To patch items, specify the GUID of the collection that contains them. For each item, specify its GUID and the modifications you want to apply. If the item is found in the specified collection with the specified GUID, that item is patched. If no such item is found, the response's `results` array contains a corresponding item whose `itemMetadata.error` property contains details about the error.  Learn more about [Wix Data error codes](https://dev.wix.com/docs/rest/business-solutions/cms/wix-data-error-codes.md).  > **Notes**: > - When an item is patched, its `data._updatedDate` property is updated to the current date and time. > - You can only patch items in [collections created by Wix users](https://support.wix.com/en/article/cms-formerly-content-manager-creating-a-collection). Items in [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code.md) cannot be patched. > - Calling this method triggers the [`Data Item Updated`](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/data-item-updated.md) event for each patched item.
 URL: https://www.wixapis.com/wix-data/v2/bulk/items/patch
 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, patches, patches.dataItemId, patches.fieldModifications, patches.fieldModifications.fieldPath, patches.fieldModifications.action
 Method parameters: 
   param name: condition | type: Condition    
        - name: filter | type: object | description: Filter, changes to item(s) will only apply if they satisfy this filter. Learn more about filters in [API Query Language](https://dev.wix.com/docs/rest/articles/get-started/api-query-language.md#filters).  
   param name: dataCollectionId | type: dataCollectionId | description: GUID of the collection that contains the items to patch. | required: true | validation: maxLength 256
   param name: patches | type: array<patches> | description: Patches to apply to the items. | required: true | validation: minItems 1, maxItems 100
              - name: dataItemId | type: string | description: GUID of the item to patch. | required: true | validation: maxLength 256
              - name: fieldModifications | type: array<FieldModification> | description: Modifications to apply. | required: true | validation: minItems 1, maxItems 100
                 - ONE-OF: 
                    - name: setFieldOptions | type: SetFieldOptions | description: Options for setting the value of the specified field. Required when `action` is `SET_FIELD`.  
                       - name: value | type: Value | description: Value to set for the specified field. This replaces the existing value.  
                          - ONE-OF: 
                             - name: nullValue | type:  | description:   
                             - name: numberValue | type: number | description:   
                             - name: stringValue | type: string | description:   
                             - name: boolValue | type: boolean | description:   
                             - name: structValue | type: object | description:   
                             - name: listValue | type: ListValue | description:   
                                - name: values | type: array<Value> | description:   
                    - name: incrementFieldOptions | type: IncrementFieldOptions | description: Options for incrementing the value of the specified field. Required when `action` is `INCREMENT_FIELD`.  
                       - name: value | type: number | description: Numerical value by which to increment the field value. To decrement, specify a negative value.  
                    - name: appendToArrayOptions | type: AppendToArrayOptions | description: Options for appending a value to the specified array or a multi-reference field. Required when `action` is `APPEND_TO_ARRAY`.  
                       - name: value | type: Value | description: Value to append to the specified array.  
                    - name: removeFromArrayOptions | type: RemoveFromArrayOptions | description: Options for removing a value from the specified array or a multi-reference field. Required when `action` is `REMOVE_FROM_ARRAY`.  
                       - name: value | type: Value | description: Value whose first instance is removed from the specified array.  
                 - name: fieldPath | type: string | description: Path of the field to be modified. For example: `title`.  Nested fields can be specified using dot notation. For example: `address.street`.  | validation: maxLength 1000
                 - name: action | type: ACTION | description: Patch action to apply to the specified field.  
                         - enum:
                         -     SET_FIELD: Sets the specified field to the specified value.
                         -     REMOVE_FIELD: Clears the specified field.
                         -     INCREMENT_FIELD: Increments the specified field by the specified value. To decrement, specify a negative value.
                         -     APPEND_TO_ARRAY: Appends the specified value to the array.  Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-types-in-wix-data.md).
                         -     REMOVE_FROM_ARRAY: Removes the first instance of the specified value from the array.  Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-types-in-wix-data.md).
   param name: publishPluginOptions | type: PublishPluginOptions    
        - name: includeDraftItems | type: boolean | description: Whether to include draft items.  When `true`, both published and draft items are affected. Default: `false`.  
   param name: returnEntity | type: returnEntity | description: Whether to return the patched data items. When `true`, each item in the `results` array contains a `dataItem` field with the full patched data item.  Default: `false`  
 Return type: BulkPatchDataItemsResponse
  - name: results | type: array<BulkDataItemResult> | description: Patched items.  
     - name: action | type: BulkActionType | description: Action attempted for the data item.  
         - enum: UNKNOWN_ACTION_TYPE, INSERT, UPDATE, DELETE, PATCH
     - name: itemMetadata | type: ItemMetadata | description: Item metadata.  
        - 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: dataItem | type: DataItem | description: Updated data item.  Returned if `returnEntity` is set to `true` and the action is successful.  
        - name: id | type: string | description: Data item GUID.  When an item is inserted into a collection, the item's GUID is automatically assigned a random value. You can optionally provide a custom GUID in `dataItem.id` when inserting the item. If you specify an GUID that already exists in the collection, the insertion will fail.  | validation: maxLength 128, immutable
        - name: dataCollectionId | type: string | description: GUID of the collection this item belongs to.  This is the user-defined collection identifier set when the collection is created (for example, `EvalCustomers`), not a GUID.  | read-only: true | validation: maxLength 256
        - name: data | type: object | description: Data item contents.  Property-value pairs representing the data item's payload. When retrieving a data item, it also includes the following read-only fields:  + `_id`: Item GUID. + `_createdDate`: Date and time the item was added to the collection. + `_updatedDate`: Date and time the item was last modified. When the item is first inserted, `_createdDate` and `_updatedDate` have the same value. + `_owner`: GUID of the user who created the item. Can be modified with site owner permissions.  
  - 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

### Patch multiple items conditionally: Decrement count only when the specified value is positive.
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v2/bulk/items/patch' \
-H 'Authorization: <AUTH>' \
-d '{
  "dataCollectionId": "MyCollection",
  "patches": [
    {
      "dataItemId": "5331fc15-9441-4fd4-bc7b-7f6870c69228",
      "fieldModifications": [
        {
          "fieldPath": "availableSeats",
          "action": "INCREMENT_FIELD",
          "incrementFieldOptions": {
            "value": -1
          }
        }
      ]
    },
    {
      "dataItemId": "01b60c9f-d793-4d21-a8d2-320c2099e56f",
      "fieldModifications": [
        {
          "fieldPath": "availableSeats",
          "action": "INCREMENT_FIELD",
          "incrementFieldOptions": {
            "value": -1
          }
        }
      ]
    }
  ],
  "condition": {
    "filter": {
       "count": {
          "$gt": 0
       }
    }
  }
}'
```

### Bulk patch items
```curl
curl -X POST \
'https://www.wixapis.com/wix-data/v2/bulk/items/patch' \
-H 'Authorization: <AUTH>' \
-d '{
  "dataCollectionId": "test",
  "patches": [
    {
      "dataItemId": "5331fc15-9441-4fd4-bc7b-7f6870c69228",
      "fieldModifications": [
        {
          "fieldPath": "state",
          "action": "SET_FIELD",
          "setFieldOptions": {
            "value": "California"
          }
        }
      ]
    },
    {
      "dataItemId": "01b60c9f-d793-4d21-a8d2-320c2099e56f",
      "fieldModifications": [
        {
          "fieldPath": "state",
          "action": "SET_FIELD",
          "setFieldOptions": {
            "value": "California"
          }
        }
      ]
    }
  ]
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.data.items.bulkPatch(dataCollectionId, itemIds, fieldModifications, options)
 Description: Patches one or more items in a collection.  Call this method when you need to apply partial changes to many items and want each item to keep fields that aren't mentioned in the request. This is also the right bulk surface for `fieldModifications` actions such as `SET_FIELD` and `INCREMENT_FIELD`: increments and decrements apply atomically on the server, so concurrent writers don't have to read the current value first or coordinate to avoid lost updates. For different behavior, you can call:  - [Bulk Update Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-update-data-items.md) to replace each item's full payload rather than patch part of it. - [Save Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/save-data-item.md) per item for upsert behavior, meaning to create the item if its GUID doesn't exist yet and update it if it does.  This method modifies the existing data of one or more items. Unlike [`Bulk Update Data Item`](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-update-data-items.md), only the fields specified in the request are modified. Data that isn't explicitly modified remains unchanged.  To patch items, specify the GUID of the collection that contains them. For each item, specify its GUID and the modifications you want to apply. If the item is found in the specified collection with the specified GUID, that item is patched. If no such item is found, the response's `results` array contains a corresponding item whose `itemMetadata.error` property contains details about the error.  Learn more about [Wix Data error codes](https://dev.wix.com/docs/rest/business-solutions/cms/wix-data-error-codes.md).  > **Notes**: > - When an item is patched, its `data._updatedDate` property is updated to the current date and time. > - You can only patch items in [collections created by Wix users](https://support.wix.com/en/article/cms-formerly-content-manager-creating-a-collection). Items in [Wix app collections](https://dev.wix.com/docs/develop-websites/articles/databases/wix-data/collections/working-with-wix-app-collections-and-code.md) cannot be patched. > - Calling this method triggers the [`Data Item Updated`](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/data-item-updated.md) event for each patched item.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  dataCollectionId, itemIds, fieldModifications
 Method parameters: 
   param name: dataCollectionId | type: string | description: GUID of the collection that contains the items to patch. | required: true | validation: maxLength 256
   param name: itemIds | type: array<string> | description: IDs of the data items to patch. | required: true 
   param name: fieldModifications | type: array<FieldModification> | description: Field modifications to apply to each item. | required: true 
              - name: fieldPath | type: string | description: Path of the field to be modified. For example: `title`.  Nested fields can be specified using dot notation. For example: `address.street`.  
              - name: action | type: ACTION | description: Patch action to apply to the specified field.  
                     - enum:
                     -     SET_FIELD: Sets the specified field to the specified value.
                     -     REMOVE_FIELD: Clears the specified field.
                     -     INCREMENT_FIELD: Increments the specified field by the specified value. To decrement, specify a negative value.
                     -     APPEND_TO_ARRAY: Appends the specified value to the array.  Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-types-in-wix-data.md).
                     -     REMOVE_FROM_ARRAY: Removes the first instance of the specified value from the array.  Learn more about [data types in Wix Data](https://dev.wix.com/docs/rest/business-solutions/cms/data-types-in-wix-data.md).
              - name: value | type: any<Value> | description: none  
                 - ONE-OF: 
                    - name: nullValue | type:  | description:   
                    - name: numberValue | type: number | description:   
                    - name: stringValue | type: string | description:   
                    - name: boolValue | type: boolean | description:   
                    - name: structValue | type: object | description:   
                    - name: listValue | type: ListValue | description:   
                       - name: values | type: array<Value> | description:   
   param name: options | type: WixDataBulkPatchOptions  none  
        - name: suppressHooks | type: boolean | description: Prevents hooks from running for the operation. Can only be used in the [backend code of a Wix site](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/backend-code/about-the-site-backend.md).  
        - name: showDrafts | type: boolean | description: When `true`, operations include draft items. Read operations include draft items in their response, and write operations modify draft items. Default: `false`.  
        - name: appOptions | type: object | description: Options for [querying Wix app collections](https://dev.wix.com/docs/develop-websites/articles/wix-apps/wix-app-collections/querying-wix-app-collections.md).  
        - name: condition | type: object | description: Filter, changes to item(s) will only apply if they satisfy this filter. Learn more about filters in [API Query Language](https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/data-retrieval/about-the-wix-api-query-language.md#filters).  
 Return type: PROMISE<WixDataBulkResult>
  - name: inserted | type: integer | description: Number of inserted items.  
  - name: updated | type: integer | description: Number of updated items.  
  - name: removed | type: integer | description: Number of removed items.  
  - name: skipped | type: integer | description: Number of skipped items.  
  - name: errors | type: array<WixDataBulkError> | description: List of errors.  
     - name: message | type: string | description: Description of the error.  
     - name: code | type: string | description: Error code.  
     - name: originalIndex | type: integer | description: Index of the item within the request array. Allows for correlation between request and response items.  
     - name: item | type: string | description: Failed item (or GUID in case of `bulkRemove()`).  
  - name: insertedItemIds | type: array<string> | description: List of GUIDs of inserted items.  
  - name: updatedItemIds | type: array<string> | description: List of GUIDs of updated items.  
  - name: removedItemIds | type: array<string> | description: List of GUIDs of removed items.  


```

### Examples

### bulkPatch
```javascript
import { items } from '@wix/data';

async function bulkPatch(dataCollectionId,itemIds,fieldModifications,options) {
  const response = await items.bulkPatch(dataCollectionId,itemIds,fieldModifications,options);
};
```

### bulkPatch (with elevated permissions)
```javascript
import { items } from '@wix/data';
import { auth } from '@wix/essentials';

async function myBulkPatchMethod(dataCollectionId,itemIds,fieldModifications,options) {
  const elevatedBulkPatch = auth.elevate(items.bulkPatch);
  const response = await elevatedBulkPatch(dataCollectionId,itemIds,fieldModifications,options);
}
```

### bulkPatch (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 { items } from '@wix/data';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { items },
  // Include the auth strategy and host as relevant
});


async function bulkPatch(dataCollectionId,itemIds,fieldModifications,options) {
  const response = await myWixClient.items.bulkPatch(dataCollectionId,itemIds,fieldModifications,options);
};
```

---