@wix/agent-skills 1.24.0 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +1 -0
  2. package/package.json +2 -1
  3. package/skills/wix-app/SKILL.md +4 -1
  4. package/skills/wix-app/references/BUSINESS_MANAGER_THEME.md +108 -0
  5. package/skills/wix-app/references/BUSINESS_MANAGER_TOKENS.md +81 -0
  6. package/skills/wix-app/references/DASHBOARD_MODAL.md +41 -0
  7. package/skills/wix-app/references/DASHBOARD_PAGE.md +2 -0
  8. package/skills/wix-app/references/DASHBOARD_PLUGIN.md +19 -4
  9. package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE.md +5 -4
  10. package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE_ROUTER.md +8 -7
  11. package/skills/wix-app/references/dashboard-page/DYNAMIC_PARAMETERS.md +21 -38
  12. package/skills/wix-headless/SKILL.md +0 -1
  13. package/skills/wix-headless/references/CAPABILITIES.md +3 -3
  14. package/skills/wix-headless/references/DISCOVERY.md +1 -1
  15. package/skills/wix-headless/references/SDK_HANDOFF.md +1 -1
  16. package/skills/wix-headless/references/SEED.md +1 -1
  17. package/skills/wix-headless/references/SETUP.md +1 -1
  18. package/skills/wix-headless/references/inline-recipes/how-to-code-restaurant-reservations.md +1 -1
  19. package/skills/wix-headless/references/inline-recipes/setup-restaurant-experiences.md +2 -2
  20. package/skills/wix-headless/references/managed/AUTHENTICATION.md +3 -14
  21. package/skills/wix-headless/scripts/bootstrap.mjs +156 -0
  22. package/skills/wix-headless-kit/SKILL.md +4 -4
  23. package/skills/wix-headless-kit/install/AGENTS.md +2 -2
  24. package/skills/wix-headless-kit/install/bootstrap.mjs +156 -0
  25. package/skills/wix-headless-kit/install/check.mjs +1 -1
  26. package/skills/wix-manage/SKILL.md +2 -8
  27. package/skills/wix-manage/references/cms/cms-data-items-crud.md +250 -18
  28. package/skills/wix-manage/references/cms/cms-schema-management.md +52 -1
  29. package/skills/wix-manage/references/cms/cms-data-operations-extended.md +0 -263
  30. package/skills/wix-manage/references/cms/cms-references-and-relationships.md +0 -162
@@ -1,12 +1,12 @@
1
1
  ---
2
2
  name: "CMS Data Items CRUD"
3
- description: "Add, query, update, and delete items in CMS collections. Use this to insert content, bulk insert/update/patch/delete items, query with filters, and manage collection data. Key endpoints: /wix-data/v2/items, /wix-data/v2/bulk/items/*."
3
+ description: "Add, query, update, and delete items in CMS collections, one at a time or in bulk. Also covers counting items, upserting with bulk save, truncating a collection, aggregating data with a pipeline, linking items through single- and multi-reference fields, and reading items with their referenced items expanded."
4
4
  ---
5
5
  # CMS Data Items CRUD
6
6
 
7
7
  > **Standard call shape (every curl below).** The `<AUTH>` placeholder is shorthand for `Authorization: Bearer <TOKEN>` only. Body-bearing requests also need `Content-Type: application/json`.
8
8
 
9
- This recipe covers basic Create, Read, Update, Delete (CRUD) operations for Wix CMS data items.
9
+ This recipe covers Create, Read, Update, Delete (CRUD) operations for Wix CMS data items, plus count, upsert, truncate, aggregate, and reference-field links.
10
10
 
11
11
  ## Prerequisites
12
12
 
@@ -231,6 +231,8 @@ Unlike Update, this only modifies the specified fields — all other fields rema
231
231
 
232
232
  **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/update`
233
233
 
234
+ > There is no update-by-filter endpoint. To update the items matching a filter, query them first (see [Query Data Items](#query-data-items)), then send their ids to bulk update or bulk patch.
235
+
234
236
  > **Important**: Use `id` (not `_id`) at the element level. The `data` object should NOT contain `_id`.
235
237
 
236
238
  ```json
@@ -297,7 +299,7 @@ Unlike bulk update, this only modifies the specified fields - other fields remai
297
299
  }
298
300
  ```
299
301
 
300
- **Setting a reference field** (single REFERENCE only):
302
+ **Setting a single `REFERENCE` field** (the value is one item ID; for `MULTI_REFERENCE` the value shape differs, see the next example):
301
303
  ```json
302
304
  {
303
305
  "dataCollectionId": "events",
@@ -318,26 +320,39 @@ Unlike bulk update, this only modifies the specified fields - other fields remai
318
320
  }
319
321
  ```
320
322
 
323
+ **Setting a `MULTI_REFERENCE` field** (verified live): the value is an **array of item IDs**, and `SET_FIELD` **replaces the whole link set**. To add links without dropping the existing ones, use [Insert Multi-Reference Links](#insert-multi-reference-links) instead. A plain string, or `APPEND_TO_ARRAY`, fails per item with `WDE0303` inside a 200 bulk response — check `results[].itemMetadata`.
324
+ ```json
325
+ {
326
+ "dataCollectionId": "Projects",
327
+ "patches": [
328
+ {
329
+ "dataItemId": "project-item-id",
330
+ "fieldModifications": [
331
+ {
332
+ "fieldPath": "team",
333
+ "action": "SET_FIELD",
334
+ "setFieldOptions": {
335
+ "value": ["alice-item-id", "bob-item-id"]
336
+ }
337
+ }
338
+ ]
339
+ }
340
+ ]
341
+ }
342
+ ```
343
+
321
344
  **Available actions**: `SET_FIELD`, `REMOVE_FIELD`, `INCREMENT_FIELD`, `APPEND_TO_ARRAY`, `REMOVE_FROM_ARRAY`
322
345
 
323
346
  > **Common error**: If you get `WDE0080: patches must not be empty`, you sent `dataItems` instead of `patches`. Use the format above.
324
347
 
325
348
  > **Recommended**: Use bulk patch instead of bulk update when you only need to change specific fields.
326
349
 
327
- > **Reference Fields**:
328
- > - **Single REFERENCE**: CAN be set during insert/update by providing the referenced item's ID as the field value (e.g., `"venue": "venue-item-id"`)
329
- > - **MULTI_REFERENCE**: **STOP** - You cannot use this recipe for multi-reference fields. They cannot be set via insert/update/patch.
330
- >
331
- > **For MULTI_REFERENCE operations (add speakers, assign tags, link categories, etc.):**
332
- > **READ [CMS References & Relationships](cms-references-and-relationships.md)** for the exact endpoints and request bodies:
333
- > - `POST https://www.wixapis.com/wix-data/v2/bulk/items/insert-references` - add references
334
- > - `POST https://www.wixapis.com/wix-data/v2/items/replace-references` - replace all references
335
- > - `POST https://www.wixapis.com/wix-data/v2/bulk/items/remove-references` - remove references
336
- >
337
- > Error `WDE0303` occurs when attempting to set multi-reference fields via data operations.
350
+ > **Reference fields**: a single `REFERENCE` field is set like any other value (`"venue": "venue-item-id"`, as above). `MULTI_REFERENCE` links are written only by a `SET_FIELD` patch (single or bulk) or by the reference endpoints in [Reference Fields](#reference-fields) below; insert, bulk insert, bulk save, PUT and bulk update all return 200 but silently drop multi-reference values (verified live) — read the item back after any of them.
338
351
 
339
352
  ## Delete Data Item
340
353
 
354
+ > Deletes are irreversible. Confirm with the user before calling either delete endpoint unless the request already names the items to remove.
355
+
341
356
  **Endpoint**: `DELETE https://www.wixapis.com/wix-data/v2/items/{itemId}?dataCollectionId={collectionId}`
342
357
 
343
358
  ```bash
@@ -357,6 +372,225 @@ curl -X DELETE \
357
372
  }
358
373
  ```
359
374
 
375
+ ## Count Data Items
376
+
377
+ Count items in a collection, optionally with filters.
378
+
379
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/count`
380
+
381
+ **Count All Items**:
382
+ ```json
383
+ {
384
+ "dataCollectionId": "Products"
385
+ }
386
+ ```
387
+
388
+ **Response**:
389
+ ```json
390
+ {
391
+ "totalCount": 42
392
+ }
393
+ ```
394
+
395
+ **Count with Filter**:
396
+ ```json
397
+ {
398
+ "dataCollectionId": "Products",
399
+ "filter": {
400
+ "$and": [
401
+ { "inStock": true },
402
+ { "price": { "$gte": 50 } }
403
+ ]
404
+ }
405
+ }
406
+ ```
407
+
408
+ Count returns only `totalCount`. When the user needs to know *which* items match, run Query Data Items with the same filter instead of, or after, counting.
409
+
410
+ ## Bulk Save (Upsert)
411
+
412
+ Insert new items or update existing items in a single operation. This is useful for syncing data.
413
+
414
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/save`
415
+
416
+ ```json
417
+ {
418
+ "dataCollectionId": "Products",
419
+ "dataItems": [
420
+ {
421
+ "id": "existing-item-id",
422
+ "data": {
423
+ "title": "Updated Product",
424
+ "price": 199.99,
425
+ "inStock": true
426
+ }
427
+ },
428
+ {
429
+ "data": {
430
+ "title": "New Product",
431
+ "price": 79.99,
432
+ "inStock": true
433
+ }
434
+ }
435
+ ],
436
+ "returnEntity": true
437
+ }
438
+ ```
439
+
440
+ | Scenario | Action |
441
+ |----------|--------|
442
+ | No `id` provided | INSERT - Creates new item with generated ID |
443
+ | `id` provided, doesn't exist | INSERT - Creates new item with provided ID |
444
+ | `id` provided, exists | UPDATE - Replaces existing item |
445
+
446
+ > **Warning**: When updating, the entire item is replaced. Include all fields you want to keep. Confirm with the user before saving over existing items.
447
+
448
+ ## Truncate Collection
449
+
450
+ Remove all items from a collection.
451
+
452
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/truncate`
453
+
454
+ ```json
455
+ {
456
+ "dataCollectionId": "TestCollection"
457
+ }
458
+ ```
459
+
460
+ > **Warning**: This permanently deletes ALL items in the collection and cannot be undone. Ask the user to confirm before calling it.
461
+
462
+ ## Aggregate Data
463
+
464
+ Perform calculations on collection data using a pipeline of sequential stages. The example shows one `group` stage; the full set of stages (`filter`, `group`, `sort`, `projection`, `unwindArray`, `skip`, `limit`) and accumulators is in the [Aggregate Pipeline Data Items reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/aggregate-pipeline-data-items).
465
+
466
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/aggregate-pipeline`
467
+
468
+ **Count by Category**:
469
+ ```json
470
+ {
471
+ "dataCollectionId": "Products",
472
+ "pipeline": {
473
+ "stages": [
474
+ {
475
+ "group": {
476
+ "groupIds": [
477
+ {"key": "category", "expression": {"fieldPath": "category"}}
478
+ ],
479
+ "accumulators": [
480
+ {
481
+ "resultFieldName": "count",
482
+ "sum": {"expression": {"numeric": 1}}
483
+ }
484
+ ]
485
+ }
486
+ }
487
+ ]
488
+ }
489
+ }
490
+ ```
491
+
492
+ ## Operation Comparison
493
+
494
+ | Operation | Use Case | Behavior |
495
+ |-----------|----------|----------|
496
+ | **Bulk Insert** | Add new items only | Fails if ID exists |
497
+ | **Bulk Update** | Update existing items | Fails if ID doesn't exist, replaces entire item |
498
+ | **Bulk Save** | Upsert (insert or update) | Creates or updates based on ID |
499
+ | **Bulk Patch** | Partial update | Only modifies specified fields |
500
+
501
+ ## Reference Fields
502
+
503
+ Reference fields link items across collections. A single `REFERENCE` field holds one item ID and is set like any other value in insert, update, or patch. A `MULTI_REFERENCE` field holds many links, and only two kinds of write create them: a `SET_FIELD` patch on the field (single or bulk), or the reference endpoints below, which add, replace, or remove links without touching the rest of the item. To add a reference field to a collection, see [Add a Reference Field](cms-schema-management.md#add-a-reference-field).
504
+
505
+ > **Warning (verified live)**: writing IDs into a `MULTI_REFERENCE` field through insert, bulk insert, bulk save, or PUT update returns **200 and silently drops that field's value** — no error is raised. Bulk update is a full-item replace like PUT and does the same: `success: true`, value dropped (verified live, bulk save on both its insert and update paths). Never trust the write response for reference links: read the item back with `includeReferencedItems` and confirm the linked items are there.
506
+
507
+ Linking flow, every time:
508
+
509
+ 1. Resolve the referring item ID and the referenced item IDs (query by a field value; never guess IDs).
510
+ 2. Write the links with the reference endpoints below, or with a `SET_FIELD` patch on the reference field. If the field already has links, `insert-references` adds without dropping them; `replace-references` and `SET_FIELD` discard the rest — confirm with the user before replacing unless the request says to.
511
+ 3. **Read the referring item back** with Query Data Items and `includeReferencedItems: ["<field>"]` (or `includeReferences: [{ "field": "<field>" }]`), and confirm the linked items are present. The write's 200 is not proof; only the read-back is.
512
+
513
+ ### Insert Multi-Reference Links
514
+
515
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/insert-references`
516
+
517
+ ```json
518
+ {
519
+ "dataCollectionId": "Products",
520
+ "dataItemReferences": [
521
+ {
522
+ "referringItemId": "product-item-id",
523
+ "referringItemFieldName": "tags",
524
+ "referencedItemId": "tag-1-item-id"
525
+ },
526
+ {
527
+ "referringItemId": "product-item-id",
528
+ "referringItemFieldName": "tags",
529
+ "referencedItemId": "tag-2-item-id"
530
+ }
531
+ ],
532
+ "returnEntity": true
533
+ }
534
+ ```
535
+
536
+ ### Replace All References
537
+
538
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/replace-references`
539
+
540
+ ```json
541
+ {
542
+ "dataCollectionId": "Products",
543
+ "referringItemId": "product-item-id",
544
+ "referringItemFieldName": "tags",
545
+ "newReferencedItemIds": ["new-tag-1-id", "new-tag-2-id", "new-tag-3-id"]
546
+ }
547
+ ```
548
+
549
+ > **Note**: To remove all references, pass an empty array for `newReferencedItemIds`.
550
+
551
+ ### Remove References (Bulk)
552
+
553
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/bulk/items/remove-references`
554
+
555
+ ```json
556
+ {
557
+ "dataCollectionId": "Products",
558
+ "dataItemReferences": [
559
+ {
560
+ "referringItemId": "product-id-1",
561
+ "referringItemFieldName": "tags",
562
+ "referencedItemId": "tag-to-remove-id"
563
+ }
564
+ ]
565
+ }
566
+ ```
567
+
568
+ ### Query with Referenced Items Expanded
569
+
570
+ **Endpoint**: `POST https://www.wixapis.com/wix-data/v2/items/query`
571
+
572
+ ```json
573
+ {
574
+ "dataCollectionId": "Products",
575
+ "query": {
576
+ "filter": {
577
+ "inStock": true
578
+ }
579
+ },
580
+ "includeReferencedItems": ["category", "tags"]
581
+ }
582
+ ```
583
+
584
+ The method article documents the same expansion as `"includeReferences": [{ "field": "category" }, { "field": "tags", "limit": 50 }]`; both forms work (verified live). Either way the expanded value is an **array of item objects** (with `_id`, `name`, …), not an array of IDs. Without one of these properties a `MULTI_REFERENCE` field is absent from the returned item, and a single `REFERENCE` field is returned as the item ID string (it is stored on the item; verified live).
585
+
586
+ ### Reference Query Operators
587
+
588
+ | Operator | Description | Example |
589
+ |----------|-------------|---------|
590
+ | `$eq` | Exact match (single reference) | `{ "category": "id" }` |
591
+ | `$hasSome` | Has at least one of | `{ "tags": { "$hasSome": ["id1", "id2"] } }` |
592
+ | `$hasAll` | Has all of | `{ "tags": { "$hasAll": ["id1", "id2"] } }` |
593
+
360
594
  ## Field Types Reference
361
595
 
362
596
  | Type | Description | Example Value |
@@ -379,7 +613,7 @@ curl -X DELETE \
379
613
  | `ARRAY_STRING` | Array of strings | `["tag1", "tag2"]` |
380
614
  | `OBJECT` | JSON object | `{"key": "value"}` |
381
615
  | `REFERENCE` | Single reference | Item ID string |
382
- | `MULTI_REFERENCE` | Multiple references, use separate *reference* endpoints to manipulate, `include` to include in queries | Array of IDs |
616
+ | `MULTI_REFERENCE` | Multiple references. Write with a `SET_FIELD` patch (array of item IDs, replaces the set) or the *reference* endpoints (add / replace / remove); expand in queries with `includeReferencedItems` or `includeReferences` | Write: array of item IDs (`SET_FIELD`). Read: absent unless expanded with `includeReferencedItems` / `includeReferences`, then an array of item objects |
383
617
 
384
618
  ---
385
619
 
@@ -465,7 +699,7 @@ confirmation before performing the install.
465
699
  | `PERMISSION_DENIED` | Insufficient access | Check API permissions |
466
700
  | `WDE0007` | Bulk update: wrong ID field name | Use `id` not `_id` at element level |
467
701
  | `WDE0080` | Validation failed (multiple causes) | Bulk update: don't include `_id` in `data`; Bulk patch: use `patches` array not `dataItems` |
468
- | `WDE0303` | Can't set multi-reference field via data operations | Use reference endpoints: `insert-references`, `replace-references` |
702
+ | `WDE0303` | Multi-reference field value is not an array of item IDs (a single ID string, or `APPEND_TO_ARRAY`); reported per item inside a 200 bulk response | Send `"value": ["id1", "id2"]` with `SET_FIELD`, or use the reference endpoints |
469
703
  | `WDE0110` | Wix CMS (Wix Data) application is not installed | Install application with appDefId: `e593b0bd-b783-45b8-97c2-873d42aacaf4` |
470
704
 
471
705
  ---
@@ -474,6 +708,4 @@ confirmation before performing the install.
474
708
 
475
709
  - [Data Items API Reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction)
476
710
  - [CMS Schema Management](cms-schema-management.md) - Creating and modifying collections
477
- - [CMS References & Relationships](cms-references-and-relationships.md) - Linking collections
478
- - [CMS Data Operations Extended](cms-data-operations-extended.md) - Count, upsert, aggregate
479
711
  - [CMS Draft & Publish Workflow](cms-publishing-flow.md) - Collections gated behind a draft/publish (Draft Items plugin) workflow
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: "CMS Schema Management"
3
- description: Create and modify CMS collection structures. Covers listing collections, creating collections with fields, adding/removing fields, and updating collection settings.
3
+ description: Create and modify CMS collection structures. Covers listing collections, creating collections with fields, adding/removing fields (including single- and multi-reference fields that link two collections), and updating collection settings.
4
4
  ---
5
5
  # CMS Schema Management
6
6
 
@@ -86,6 +86,55 @@ curl -X GET \
86
86
  }
87
87
  ```
88
88
 
89
+ ### Add a Reference Field
90
+
91
+ Same endpoint as above: `POST https://www.wixapis.com/wix-data/v2/collections/create-field`. The two bodies below differ only in `type` and `typeMetadata`; omitting `typeMetadata` fails with `WDE0075` (see Error Handling).
92
+
93
+ | Type | Field Type | Relationship | Example |
94
+ |------|------------|--------------|---------|
95
+ | Single Reference | `REFERENCE` | One-to-one, Many-to-one | Product → Category |
96
+ | Multi-Reference | `MULTI_REFERENCE` | One-to-many, Many-to-many | Product → Tags |
97
+
98
+ **Single reference** — `typeMetadata.reference` names the referenced collection:
99
+
100
+ ```json
101
+ {
102
+ "dataCollectionId": "Products",
103
+ "field": {
104
+ "key": "category",
105
+ "displayName": "Category",
106
+ "type": "REFERENCE",
107
+ "typeMetadata": {
108
+ "reference": {
109
+ "referencedCollectionId": "Categories"
110
+ }
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ **Multi-reference** — `typeMetadata.multiReference` also names the field created on the other collection:
117
+
118
+ ```json
119
+ {
120
+ "dataCollectionId": "Products",
121
+ "field": {
122
+ "key": "tags",
123
+ "displayName": "Tags",
124
+ "type": "MULTI_REFERENCE",
125
+ "typeMetadata": {
126
+ "multiReference": {
127
+ "referencedCollectionId": "Tags",
128
+ "referencingFieldKey": "products",
129
+ "referencingDisplayName": "Products"
130
+ }
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ To link items through these fields, see [Reference Fields](cms-data-items-crud.md#reference-fields) in the CMS Data Items CRUD recipe.
137
+
89
138
  ## Delete a Field from Collection
90
139
 
91
140
  > **Warning**: This permanently deletes all data stored in this field across all items.
@@ -170,6 +219,8 @@ Don't delete and recreate a collection just to change its permissions — this f
170
219
 
171
220
  | Error | Cause | Solution |
172
221
  |-------|-------|----------|
222
+ | `WDE0075` (`Metadata for Reference type field not provided`) | `create-field` with `type` REFERENCE or MULTI_REFERENCE but no `typeMetadata` | Send `typeMetadata.reference.referencedCollectionId` (or `typeMetadata.multiReference…`), see Add a Reference Field |
223
+ | `WDE0075` (`Not recognized role provided in permissions`) | `PATCH /collections/{id}` with a `permissions` change | Use the full-replace `PUT /collections` (see Update Collection Settings) or the Data Permissions API |
173
224
  | `WDE0110` | Wix CMS (Wix Data) app is not installed on the site | Install it: `POST https://www.wixapis.com/apps-installer-service/v1/app-instance/install` with body `{"tenant":{"tenantType":"SITE","id":"<SITE_ID>"},"appInstance":{"appDefId":"e593b0bd-b783-45b8-97c2-873d42aacaf4"}}`, then retry. See the [Install Wix Apps recipe](../app-installation/install-wix-apps.md). |
174
225
 
175
226
  ## Related Documentation
@@ -1,263 +0,0 @@
1
- ---
2
- name: "CMS Data Operations Extended"
3
- description: Additional CMS data operations including count, upsert (bulk save), and update by filter patterns.
4
- ---
5
- # CMS Data Operations Extended
6
-
7
- This recipe covers additional CMS data operations not included in the basic CRUD recipe.
8
-
9
- ## Prerequisites
10
-
11
- 1. Wix CMS enabled on the site
12
- 2. Collections created with data
13
- 3. API access with CMS permissions
14
-
15
- ## Required APIs
16
-
17
- - **Data Items API**: [REST](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction)
18
-
19
- ## Count Data Items
20
-
21
- Count items in a collection, optionally with filters.
22
-
23
- **Endpoint**: `POST /wix-data/v2/items/count`
24
-
25
- **Count All Items**:
26
- ```bash
27
- curl -X POST \
28
- 'https://www.wixapis.com/wix-data/v2/items/count' \
29
- -H 'Content-Type: application/json' \
30
- -H 'Authorization: <AUTH>' \
31
- -d '{
32
- "dataCollectionId": "Products"
33
- }'
34
- ```
35
-
36
- **Response**:
37
- ```json
38
- {
39
- "totalCount": 42
40
- }
41
- ```
42
-
43
- **Count with Filter**:
44
- ```bash
45
- curl -X POST \
46
- 'https://www.wixapis.com/wix-data/v2/items/count' \
47
- -H 'Content-Type: application/json' \
48
- -H 'Authorization: <AUTH>' \
49
- -d '{
50
- "dataCollectionId": "Products",
51
- "filter": {
52
- "inStock": true
53
- }
54
- }'
55
- ```
56
-
57
- **Count with Complex Filter**:
58
- ```json
59
- {
60
- "dataCollectionId": "Products",
61
- "filter": {
62
- "$and": [
63
- { "inStock": true },
64
- { "price": { "$gte": 50 } }
65
- ]
66
- }
67
- }
68
- ```
69
-
70
- ## Bulk Save (Upsert)
71
-
72
- Insert new items or update existing items in a single operation. This is useful for syncing data.
73
-
74
- **Endpoint**: `POST /wix-data/v2/bulk/items/save`
75
-
76
- **Request Body**:
77
- ```json
78
- {
79
- "dataCollectionId": "Products",
80
- "dataItems": [
81
- {
82
- "id": "existing-item-id",
83
- "data": {
84
- "title": "Updated Product",
85
- "price": 199.99,
86
- "inStock": true
87
- }
88
- },
89
- {
90
- "data": {
91
- "title": "New Product",
92
- "price": 79.99,
93
- "inStock": true
94
- }
95
- }
96
- ],
97
- "returnEntity": true
98
- }
99
- ```
100
-
101
- ### Bulk Save Behavior
102
-
103
- | Scenario | Action |
104
- |----------|--------|
105
- | No `id` provided | INSERT - Creates new item with generated ID |
106
- | `id` provided, doesn't exist | INSERT - Creates new item with provided ID |
107
- | `id` provided, exists | UPDATE - Replaces existing item |
108
-
109
- > **Warning**: When updating, the entire item is replaced. Include all fields you want to keep.
110
-
111
- ## Update by Filter Pattern
112
-
113
- Wix CMS doesn't have a direct "update by filter" API. Use this two-step pattern:
114
-
115
- ### 3.1: Query Items to Update
116
-
117
- ```bash
118
- curl -X POST \
119
- 'https://www.wixapis.com/wix-data/v2/items/query' \
120
- -H 'Content-Type: application/json' \
121
- -H 'Authorization: <AUTH>' \
122
- -d '{
123
- "dataCollectionId": "Products",
124
- "query": {
125
- "filter": {
126
- "category": "electronics"
127
- }
128
- }
129
- }'
130
- ```
131
-
132
- ### 3.2: Bulk Update Those Items
133
-
134
- > **Important**: Use `id` (not `_id`) at the element level. The `data` object should NOT contain `_id`.
135
-
136
- ```bash
137
- curl -X POST \
138
- 'https://www.wixapis.com/wix-data/v2/bulk/items/update' \
139
- -H 'Content-Type: application/json' \
140
- -H 'Authorization: <AUTH>' \
141
- -d '{
142
- "dataCollectionId": "Products",
143
- "dataItems": [
144
- {
145
- "id": "item-1-from-query",
146
- "data": {
147
- "title": "Updated Title 1",
148
- "price": 99.99,
149
- "onSale": true
150
- }
151
- },
152
- {
153
- "id": "item-2-from-query",
154
- "data": {
155
- "title": "Updated Title 2",
156
- "price": 149.99,
157
- "onSale": true
158
- }
159
- }
160
- ]
161
- }'
162
- ```
163
-
164
- ### Alternative: Bulk Patch (Partial Update)
165
-
166
- If you only want to update specific fields without replacing the entire item, use Bulk Patch:
167
-
168
- **Endpoint**: `POST /wix-data/v2/bulk/items/patch`
169
-
170
- > **Important**: This endpoint uses `patches` array with `fieldModifications`, NOT `dataItems`. Do not confuse with bulk update.
171
-
172
- ```bash
173
- curl -X POST \
174
- 'https://www.wixapis.com/wix-data/v2/bulk/items/patch' \
175
- -H 'Content-Type: application/json' \
176
- -H 'Authorization: <AUTH>' \
177
- -d '{
178
- "dataCollectionId": "Products",
179
- "patches": [
180
- {
181
- "dataItemId": "item-1",
182
- "fieldModifications": [
183
- {
184
- "fieldPath": "onSale",
185
- "action": "SET_FIELD",
186
- "setFieldOptions": {
187
- "value": true
188
- }
189
- }
190
- ]
191
- }
192
- ]
193
- }'
194
- ```
195
-
196
- > **Common error**: If you get `WDE0080: patches must not be empty`, you sent `dataItems` instead of `patches`. Use the format above.
197
-
198
- ## Truncate Collection
199
-
200
- Remove all items from a collection (dangerous operation).
201
-
202
- **Endpoint**: `POST /wix-data/v2/items/truncate`
203
-
204
- ```bash
205
- curl -X POST \
206
- 'https://www.wixapis.com/wix-data/v2/items/truncate' \
207
- -H 'Content-Type: application/json' \
208
- -H 'Authorization: <AUTH>' \
209
- -d '{
210
- "dataCollectionId": "TestCollection"
211
- }'
212
- ```
213
-
214
- > **Warning**: This permanently deletes ALL items in the collection. Use with extreme caution.
215
-
216
- ## Aggregate Data
217
-
218
- Perform calculations on collection data using a pipeline of sequential stages.
219
-
220
- **Endpoint**: `POST /wix-data/v2/items/aggregate-pipeline`
221
-
222
- **Count by Category**:
223
- ```bash
224
- curl -X POST \
225
- 'https://www.wixapis.com/wix-data/v2/items/aggregate-pipeline' \
226
- -H 'Content-Type: application/json' \
227
- -H 'Authorization: <AUTH>' \
228
- -d '{
229
- "dataCollectionId": "Products",
230
- "pipeline": {
231
- "stages": [
232
- {
233
- "group": {
234
- "groupIds": [
235
- {"key": "category", "expression": {"fieldPath": "category"}}
236
- ],
237
- "accumulators": [
238
- {
239
- "resultFieldName": "count",
240
- "sum": {"expression": {"numeric": 1}}
241
- }
242
- ]
243
- }
244
- }
245
- ]
246
- }
247
- }'
248
- ```
249
-
250
- ## Operation Comparison
251
-
252
- | Operation | Use Case | Behavior |
253
- |-----------|----------|----------|
254
- | **Bulk Insert** | Add new items only | Fails if ID exists |
255
- | **Bulk Update** | Update existing items | Fails if ID doesn't exist, replaces entire item |
256
- | **Bulk Save** | Upsert (insert or update) | Creates or updates based on ID |
257
- | **Bulk Patch** | Partial update | Only modifies specified fields |
258
-
259
- ## Related Documentation
260
-
261
- - [Data Items API Reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction)
262
- - [CMS Operations Best Practices](cms-data-items-crud.md)
263
- - [CMS Schema Management](cms-schema-management.md)