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.
Install the @wix/site
package using npm or Yarn:
or
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:
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:
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:
The way you call backend modules depends on the development framework you're using to build your app.
To use backend modules in Wix-hosted apps, import and call the module's methods the same way you would a frontend module.
To use backend modules in self-hosted apps, you need to create a client with the Site API host and 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.
The following example creates and uses a client to call a backend method.
The following example creates and uses a client to call a backend and frontend methods.