> 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

## Resource: Sample Flows

## Article: Sample Flows

## Article Link: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/sample-flows.md

## Article Content:

# Data Items API: Sample Use Cases & Flows

This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.

## Populate a tutorials collection with content

You can use the Data Items API to programmatically add content to an existing collection.

This flow uses bulk operations to efficiently add multiple tutorials into [an existing tutorials collection](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections/sample-flows.md).

To populate the tutorials collection:

1. Call [Bulk Insert Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-insert-data-items.md) with `dataCollectionId` set to `tutorials`. For each `dataItem`, include `fields` as structured in the data collection to be inserted. For reference fields like `category` and `author`, provide the ID of the referenced item from their respective collections.
1. Check the `results` array in the response to confirm each item inserted successfully. If any items fail, the `itemMetadata.error` property of the corresponding entry contains details about the error.

## Query tutorials by category

You can retrieve tutorials from [an existing tutorials collection](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections/sample-flows.md) filtered by category and sorted by publish date. This is useful for displaying a list of tutorials in a specific topic area.

To query tutorials by category:

1. Call [Query Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/query-data-items.md) with `dataCollectionId` set to `tutorials` and filter by `category` sorted by `publishDate`.

## Get tutorial statistics by category

You can calculate aggregate statistics across tutorials in [an existing tutorials collection](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections/sample-flows.md), such as the total number of tutorials and average reading time per category. This is useful for analytics dashboards or category overview pages.

To aggregate tutorial data:

1. Call [Aggregate Data Items](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/aggregate-data-items.md) with `dataCollectionId` set to `tutorials`.
1. In the `aggregation` object, set `groupingFields` to `["category"]` to group results by category.
1. In the `operations` array, add aggregation operations:
    - Add an operation with `resultFieldName` set to `totalTutorials` and `itemCount` set to an empty object to count tutorials per category.
    - Add an operation with `resultFieldName` set to `avgReadingTime`, `average.itemFieldName` set to `estimatedTime` to calculate the average reading time.
1. The response contains 1 result per category with the calculated `totalTutorials` and `avgReadingTime` values.

## Archive outdated tutorials asynchronously

You can patch a large set of items in the background when the target items are defined by a filter instead of a fixed list of IDs.

For example, you can mark all tutorials published before a cutoff date as archived without sending individual item IDs in the request.

To archive outdated tutorials:

1. Call [Async Patch Data Items By Filter](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/async-patch-data-items-by-filter.md) with `dataCollectionId` set to `tutorials`.
1. In `filter`, target the items you want to archive, such as tutorials published before a given date.
1. In `fieldModifications`, set `archived` to `true`.
1. Store the `jobId` returned in the response.
1. Poll [Get Async Job Status](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/get-async-job-status.md) until the job reaches `SUCCEEDED` or `FAILED`.

## Publish content through the editorial draft lifecycle

You can use the Data Items API to author content as drafts, publish drafts to the live collection, and retract published items back to draft when revisions are needed. This flow uses [an existing tutorials collection](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections/sample-flows.md) with the draft-items plugin enabled.

To publish a new tutorial through the draft lifecycle:

1. Call [Insert Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/insert-data-item.md) with `dataCollectionId` set to `tutorials__drafts` to create a draft. Include the tutorial fields in `dataItem.data`.
1. Edit the draft as needed via [Update Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/update-data-item.md) or [Patch Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/patch-data-item.md), again with `dataCollectionId` set to `tutorials__drafts`.
1. Call [Publish Data Item Draft](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/publish-data-item-draft.md) with `dataCollectionId` set to `tutorials` (the published collection ID) and `dataItemId` set to the draft's ID. The draft is deleted and the published collection now contains the live tutorial.

To revise a published tutorial while keeping it live on the site:

1. Call [Create Data Item Draft](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/create-data-item-draft.md) with `dataCollectionId` set to `tutorials` and `dataItemId` set to the published tutorial's ID. A draft seeded with the current published data is created in `tutorials__drafts`. The published tutorial remains unchanged.
1. Edit the draft via [Update Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/update-data-item.md) or [Patch Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/patch-data-item.md) with `dataCollectionId` set to `tutorials__drafts`.
1. Call [Publish Data Item Draft](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/publish-data-item-draft.md) with `dataCollectionId` set to `tutorials` and `dataItemId` set to item to be published to put the revised tutorial live.

To revise a published tutorial by taking it offline first:

1. Call [Unpublish Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/unpublish-data-item.md) with `dataCollectionId` set to `tutorials` and `dataItemId` set to the published tutorial's ID. The published copy is removed and a draft is created in `tutorials__drafts`.
1. Edit the draft via [Update Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/update-data-item.md) or [Patch Data Item](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/patch-data-item.md) with `dataCollectionId` set to `tutorials__drafts`.
1. Call [Publish Data Item Draft](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/publish-data-item-draft.md) with `dataCollectionId` set to `tutorials` to put the revised tutorial back live.

## Publish a batch of reviewed drafts

After editors review several tutorial drafts, you can publish them in one request while tracking any items that need attention.

To publish the reviewed drafts:

1. Call [Bulk Publish Data Item Drafts](https://dev.wix.com/docs/rest/business-solutions/cms/data-items/bulk-publish-data-item-drafts.md) with `dataCollectionId` set to `tutorials` and `dataItemIds` set to the IDs of the reviewed drafts. Set `returnEntity` to `true` if you need the published items in the response.
1. Check each entry in `results`. Use `itemMetadata.originalIndex` to match it to the corresponding ID in `dataItemIds`. If `itemMetadata.success` is `false`, inspect `itemMetadata.error` and address that item separately.