Authenticate using the Wix Client in Self-Hosted Embedded Script Extensions

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.

Script types

Before starting to code, check whether your scripts are standard JavaScript scripts or JavaScript modules (ESM).

  • Standard JavaScript scripts either have no type specified or specify type="text/javascript" in the script tags.
  • JavaScript modules specify 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.

JavaScript modules (ESM)

In JavaScript modules, you need to export a function that Wix uses to inject your client with an access token to call backend modules.

  1. For the script in which you want to call SDK methods, add accesstoken="true" to your script tag.
  2. Create a client using Site host context and Site authentication.
  3. Export a function exactly like this:
    Copy
    1
    Wix calls this function to inject your client with an access token.
  4. Use the client to call SDK methods.

Example

The following example uses an authenticated client to call:

  • products.queryProducts from the @wix/stores backend module
  • seo.title from the @wix/site-seo frontend module
Copy
1

Standard JavaScript scripts

In standard JavaScript scripts, you don't need to provide Wix with any injector functions.

  1. Create a JavaScript file to host your code. This file will be your scripts src.
  2. Create a client using Site host context and Site authentication.
  3. Use the client to call SDK methods.
  4. Create your script and add your JavaScript file as the script's src.

Example

The following example uses an authenticated client to call:

  • products.queryProducts from the @wix/stores backend module
  • seo.title from the @wix/site-seo frontend module
Copy
1
Was this helpful?
Yes
No