In a self-hosted embedded script extension, you need to use a Wix Client to call Wix APIs using the SDK.
Note: We recommend always creating your client using Site host context and authentication so it can be used to call frontend and backend modules.
Before starting to code, check whether your scripts are standard JavaScript scripts or JavaScript modules (ESM).
type="text/javascript"
in the script tags.type="module"
in the script tags and they use the import
syntax.Note: Most modern build tools like Vite
and esBuild
output ESM bundles, so make sure to check your app's configuration.
In JavaScript modules, you need to export a function that Wix uses to inject your client with an access token to call backend modules.
accesstoken="true"
to your script tag.The following example uses an authenticated client to call:
products.queryProducts
from the @wix/stores
backend moduleseo.title
from the @wix/site-seo
frontend moduleIn standard JavaScript scripts, you don't need to provide Wix with any injector functions.
src
.src
.The following example uses an authenticated client to call:
products.queryProducts
from the @wix/stores
backend moduleseo.title
from the @wix/site-seo
frontend module