> 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: About the Data API

## Article: About the Data API

## Article Link: https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/about-the-data-api.md

## Article Content:

# About the Data API

The Data API gives Studio Two site code direct access to a site's data. Use it to add, update, remove, and query items, run aggregations, and manage collections and indexes.

The Data API is in the `@wix/data` package, which is preinstalled in every Studio Two site. Import the APIs you need. For example:

```javascript
import { items, collections } from "@wix/data";
```

## APIs

The Data API includes several APIs. The main ones are:

- [`items`](https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/introduction?apiView=SDK.md): Work with the items in collections. Includes adding, updating, and removing items, bulk operations, queries with filters and sorting, and aggregations.
- [`collections`](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/data-collections?apiView=SDK.md): Create collections and manage their fields and permissions.
- [`indexes`](https://dev.wix.com/docs/api-reference/business-solutions/cms/collection-management/indexes?apiView=SDK.md): Speed up queries by managing a collection's indexes.
- [`externalDatabaseConnections`](https://dev.wix.com/docs/api-reference/business-solutions/cms/external-databases/external-database-connection/introduction?apiView=SDK.md): Connect [external databases](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/external-databases/about-external-databases.md) to a site.

The `items` API also includes [data events](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/about-data-events.md), which run backend code after an item is created, updated, or deleted.

The API reference pages sometimes mention `$w`, data hooks, or a `suppressHooks` option. Studio Two has no `$w` API and no data hooks, so those don't apply.

For every API, see the [CMS API reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/introduction?apiView=SDK.md).

## Where you use the Data API

You can call the Data API from:

- **Backend code**: Backend extensions that you add with Wix Extension Builder, such as an [HTTP endpoint](https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-backend/http-endpoints/about-http-endpoints.md) or a [Backend Events extension](https://dev.wix.com/docs/studio-two/code-your-site/build-a-custom-backend/backend-events/add-a-backend-events-extension-in-studio-two.md).
- **Frontend code**: Code that runs in the browser, such as an Editor React Component (ERC) or a Data Source.
- **Wix Data view scripts**: One-off scripts that you run from the **Wix Data** view in the Code tab, without adding them to the site's code. In scripts, the `items` API is available as `wixData`, with no import. See [Query Items](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/query-items.md#try-a-query-in-a-wix-data-script).

> **Note:** The code examples in these articles use `await`. In site code, run them inside an `async` function.

## Permissions

The `items` API follows the role-based [permissions](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/introduction/about-collections.md#permissions) of each collection. A collection's permissions decide who can read, add, update, and remove its items, such as anyone, site members, or only admins. A request fails if its caller doesn't have permission for the operation. A Wix Data view script runs with the permissions of the credentials that the view is connected with. With a CLI login, that's the logged-in Wix user. With an API key, it's the permissions that the key grants.

### Elevate permissions

In backend code, you can run a method with [elevated permissions](https://dev.wix.com/docs/overview/auth-permissions/elevation.md) using [`auth.elevate()`](https://dev.wix.com/docs/sdk/core-modules/essentials/auth.md) from `@wix/essentials`. This overrides the collection's permissions for that call. For example:

```javascript
import { items } from "@wix/data";
import { auth } from "@wix/essentials";

const elevatedInsert = auth.elevate(items.insert);
const result = await elevatedInsert("Listings", { title: "Garden Flat" });
```

Elevate only in backend code. Before you pass visitor input to an elevated method, validate it, because the elevated call ignores the collection's permissions.

## Eventual consistency

Wix stores a site's data in a primary database and replicates it to mirror databases around the world, so queries are fast wherever they're made from. Mirror databases catch up with the primary database shortly after a change, but in the meantime a query might not include the change yet, if it's answered by a mirror database that hasn't received the update. This behavior is called eventual consistency.

When you need the latest data immediately after a change, pass `{ consistentRead: true }` as the query's third argument. The query then reads from the primary database, which can be slower, and its results aren't [cached](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/about-cached-queries.md). For example:

```javascript
import { items } from "@wix/data";

const results = await items.query(
  "Listings",
  { filter: { status: "available" } },
  { consistentRead: true }
);
```

Learn more about [eventual consistency](https://dev.wix.com/docs/api-reference/business-solutions/cms/eventual-consistency.md).

## See also

- [Query Items](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/query-items.md)
- [Manage Items](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/manage-items.md)
- [About Data Events](https://dev.wix.com/docs/studio-two/code-your-site/work-with-data/data-api/about-data-events.md)
- [CMS API reference](https://dev.wix.com/docs/api-reference/business-solutions/cms/introduction?apiView=SDK.md)