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:
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.
auth
)There are a number of different authorization strategies you can use with the auth
parameter.
The correct strategy to use depends on:
The following table outlines the supported authorization strategies, the cases they apply to, and the parameters needed to create the strategies:
Auth strategy | Supported Contexts | Identities | Parameters |
---|---|---|---|
OAuthStrategy | Headless project | Site visitor, site member | Client ID, Tokens (when resuming a session) |
AppStrategy | Wix 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) |
ApiKeyStrategy | Headless project, Wix app | API key | API Key |
Host module auth | Wix app (frontend interfaces) | Site visitor, site member, Wix user | - |
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.
host
)Depending on the context in which you are making API calls, you may need to specify a host
.
host()
function to specify the host when creating a client.host
when creating a client.host
when creating a client.host
.Each hosted context has it's own host module. The host modules are:
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.
Create a client to call Bookings Services APIs as a site visitor using the OAuthStrategy
for a Headless project:
Create a client to call Bookings Services APIs as the Wix app identity using the AppStrategy
for a Wix app:
Create a client to call Bookings Services and Dashboard APIs as a Wix user using the dashboard host for a Wix app:
Create a client to call Bookings Services and Editor APIs as a site visitor or member using the editor host for a Wix app:
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:
Create a client to call Bookings Services APIs using using the ApiKeyStrategy
for a Headless project or Wix app: