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:

Copy

APIs

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

  • items: Work with the items in collections. Includes adding, updating, and removing items, bulk operations, queries with filters and sorting, and aggregations.
  • collections: Create collections and manage their fields and permissions.
  • indexes: Speed up queries by managing a collection's indexes.
  • externalDatabaseConnections: Connect external databases to a site.

The items API also includes data events, 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.

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 or a Backend Events extension.
  • 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.

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 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 using auth.elevate() from @wix/essentials. This overrides the collection's permissions for that call. For example:

Copy

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. For example:

Copy

Learn more about eventual consistency.

See also

Last updated: 2 November 2026

Did this help?