Site API

The Site API enables code within Embedded Scripts and Site Widgets created with the CLI to interact with a Wix site. For example, you can access site data and interact with other Wix Apps, such as Wix Stores and Wix Bookings.

Note: This API is only available for use in Wix Apps that run within a Wix site environment. It isn't compatible with Velo code executed in the Wix Editor or on sites not hosted by Wix.

Setup

Install the @wix/site package using npm or Yarn:

Copy

or

Copy

Wix-hosted apps

To use the Site API in Wix-hosted apps, import one of the frontend SDK modules in your code and call its methods directly. Supported modules are listed under Frontend Modules in the menu of this SDK reference. The following example uses the seo module:

Copy

Self-hosted apps

To use the Site API in self-hosted apps, first create a Wix Client with the relevant frontend modules. Supported modules are listed under Frontend Modules in the menu of this SDK reference. The following example uses the seo module:

Copy

Note: You can find your app ID in the OAuth page of the Wix Dev Center.

Finally, use the client constant to call the frontend module's methods. For example:

Copy

Using Backend Modules

The way you call backend modules depends on the development framework you're using to build your app.

Wix-hosted apps

To use backend modules in Wix-hosted apps, import and call the module's methods the same way you would a frontend module.

Self-hosted apps

To use backend modules in self-hosted apps, you need to create a client with the Site API host and auth.

Auth

Use site.auth() to authenticate your client for use in site extensions.

site.auth() needs an access token to authenticate your client to call methods of backend modules. See how to provide your client with an access token for:

Note: Each site extension implements the above methods in a different way. The articles linked to above demonstrate how to implement each method in different site extensions.

Examples

The following example creates and uses a client to call a backend method.

Copy

The following example creates and uses a client to call a backend and frontend methods.

Copy
Did this help?