Manage Items

Use the Data API to add, update, and remove items in a site's collections. This article covers each operation and its bulk version.

The examples call the Data API from site code, such as a backend extension. They use await, so run them inside an async function. Each call succeeds only if the caller has permission for the operation.

Insert an item

Insert Data Item adds an item to a collection. Pass the collection ID and the item's data. The response is the new item, including its system fields.

If you don't set _id, Wix generates one. If you set an _id that already exists in the collection, the insert fails.

This example adds a listing to the Listings collection:

Copy

You can also call Save Data Item to add an item. If an item with the same _id already exists, it updates that item instead.

Update an item

Update Data Item replaces an existing item. Pass the collection ID and the complete item, including its _id. The response is the updated item.

Update Data Item replaces the whole item. Any field that you leave out loses its value. To keep the fields you aren't changing, get the item first and update a copy of it, or patch the item instead.

This example changes the price and status of a listing:

Copy

Change some fields of an item

Patch Data Item changes only the fields that you specify and leaves the item's other fields as they are. You don't need to get the item first, and you don't overwrite changes that someone else made to other fields in the meantime.

Call items.patch() with the collection ID, the item's ID, and an array of field modifications. Each modification sets a fieldPath, an action such as SET_FIELD or INCREMENT_FIELD, and a value.

This example changes a listing's status and increments its days on market:

Copy

You can't patch items in Wix app collections.

Remove an item

Remove Data Item deletes an item from a collection. Pass the collection ID and the item's ID. The response is the deleted item.

This example removes a listing:

Copy

Work with many items at once

To add, update, or remove several items, use the bulk methods. They're faster than calling the single-item methods in a loop, and each call accepts up to 1000 items. Each single-item method has a bulk version, such as:

This example adds three listings in one call:

Copy

The response reports the number of items inserted, and their IDs in insertedItemIds. Items that fail individually appear in errors, with their position in the request array in originalIndex, and the call itself still succeeds. Items whose _id already exists in the collection aren't inserted, and are counted in skipped. Skipped items don't appear in errors. To find them, compare the IDs you sent with insertedItemIds. If the caller doesn't have permission to insert items in the collection, the whole call fails.

Handle errors

A Data API call fails, and its promise is rejected, in cases such as these:

  • The caller doesn't have permission for the operation.
  • An insert sets an _id that already exists in the collection.

To handle a failure, wrap the call in try...catch. For the error codes and what they mean, see Wix Data Error Codes. For example:

Copy

Right after you change data, a query might not include the change yet. See Eventual consistency.

See also

Last updated: 2 November 2026

Did this help?