This recipe covers additional CMS data operations not included in the basic CRUD recipe.
Count items in a collection, optionally with filters.
Endpoint: POST /wix-data/v2/items/count
Count All Items:
Response:
Count with Filter:
Count with Complex Filter:
Insert new items or update existing items in a single operation. This is useful for syncing data.
Endpoint: POST /wix-data/v2/bulk/items/save
Request Body:
| Scenario | Action |
|---|---|
No id provided | INSERT - Creates new item with generated ID |
id provided, doesn't exist | INSERT - Creates new item with provided ID |
id provided, exists | UPDATE - Replaces existing item |
Warning: When updating, the entire item is replaced. Include all fields you want to keep.
Wix CMS doesn't have a direct "update by filter" API. Use this two-step pattern:
Important: Use id (not _id) at the element level. The data object should NOT contain _id.
If you only want to update specific fields without replacing the entire item, use Bulk Patch:
Endpoint: POST /wix-data/v2/bulk/items/patch
Important: This endpoint uses patches array with fieldModifications, NOT dataItems. Do not confuse with bulk update.
Common error: If you get WDE0080: patches must not be empty, you sent dataItems instead of patches. Use the format above.
Remove all items from a collection (dangerous operation).
Endpoint: POST /wix-data/v2/items/truncate
Warning: This permanently deletes ALL items in the collection. Use with extreme caution.
Perform calculations on collection data using a pipeline of sequential stages.
Endpoint: POST /wix-data/v2/items/aggregate-pipeline
Count by Category:
| Operation | Use Case | Behavior |
|---|---|---|
| Bulk Insert | Add new items only | Fails if ID exists |
| Bulk Update | Update existing items | Fails if ID doesn't exist, replaces entire item |
| Bulk Save | Upsert (insert or update) | Creates or updates based on ID |
| Bulk Patch | Partial update | Only modifies specified fields |