About the Wix Client

Use a Wix Client to make authenticated calls to the Wix JavaScript SDK.

Depending on the context you are developing in, you may or may not need to create a client:

  • Self-hosted: In self-hosted apps and Headless projects, you need to use a Wix Client to manage the authentication of calls to the Wix JavaScript SDK.
  • Wix-hosted: Apps created in Wix native frameworks, such as the Wix CLI do not require you to explicitly use a client. You can call the SDK directly and authentication is taken care of for you.

In cases where you need to create a client, you call the createClient() function and provide values for the following parameters:

  • auth: The authorization strategy used to authorize your calls to the SDK.
  • host: The host, when calling the SDK from a hosted context, such as the dashboard or editor.
  • modules: The SDK modules you want to call using this client.

Refer to the examples below to see how to create a client using these parameters for a number of different scenarios.

Authorization strategy (auth)

There are a number of different authorization strategies you can use with the auth parameter.

The correct strategy to use depends on:

  • The context in which you are making API calls. For example, whether you are calling the SDK from a Headless project or a Wix app.
  • The identity you are using to call the API. For example, whether you are calling the SDK as a site visitor or as as Wix app. Note that each function in the SDK can only be called by the identities specified in the SDK reference.

The following table outlines the supported authorization strategies, the cases they apply to, and the parameters needed to create the strategies:

Auth strategySupported ContextsIdentitiesParameters
OAuthStrategyHeadless projectSite visitor, site memberClient ID, Tokens (when resuming a session)
AppStrategyWix app (backend interfaces)Wix app, Wix user (when using elevation), Site visitor or site member (when passing an access token from the frontend)App ID, App secret, App instance ID (when authenticating with the Wix App identity), App public key (when using webhooks or service plugins), Tokens (when authenticating as a site visitor or site member)
ApiKeyStrategyHeadless project, Wix appAPI keyAPI Key
Host module authWix app (frontend interfaces)Site visitor, site member, Wix user-

Host module auth

When creating a client within a hosted context, such as the dashboard or the editor, use the host's specific authorization strategy by calling the host module's auth() function. For example, dashboard.auth().

If you are only calling frontend modules from the editor or site, you can omit the authentication altogether.

The identity used by a client created with a host authorization strategy depends on which host is being used. Within the dashboard, the identity is Wix user. In the editor or site, the identity is site visitor or site member.

Hosted context (host)

Depending on the context in which you are making API calls, you may need to specify a host.

  • In self-hosted apps:
    • When working in a hosted context, such as the dashboard or editor, use the relevant host module's host() function to specify the host when creating a client.
    • When working in a non-hosted context, such as your app backend, do not specify a host when creating a client.
  • In Headless projects, you never need specify a host when creating a client.
  • In apps created with the Wix CLI, you don't use a client, so you never need specify a host.

Each hosted context has it's own host module. The host modules are:

SDK Modules (modules)

In all cases, when creating a client, you need to specify which SDK modules you will call using that client. Simply list the imported modules you want to call.

Examples

Headless as a visitor

Create a client to call Bookings Services APIs as a site visitor using the OAuthStrategy for a Headless project:

Copy
1

Wix app as a Wix app

Create a client to call Bookings Services APIs as the Wix app identity using the AppStrategy for a Wix app:

Copy
1

Wix app as a Wix user in the dashboard

Create a client to call Bookings Services and Dashboard APIs as a Wix user using the dashboard host for a Wix app:

Copy
1

Wix app as a site visitor or member in the editor (or site)

Create a client to call Bookings Services and Editor APIs as a site visitor or member using the editor host for a Wix app:

Copy
1

Wix app as a visitor or member in the backend

Call Bookings Services APIs as a site visitor or member in the backend of a Wix app. To do so, you need to pass a visitor or member access token from the frontend:

Copy
1
Copy
1

Headless or Wix app using an API Key

Create a client to call Bookings Services APIs using using the ApiKeyStrategy for a Headless project or Wix app:

Copy
1
Was this helpful?
Yes
No