Set Up a Wix Client

A Wix client is an object you create in your code to make authenticated calls to the Wix JavaScript SDK from self-hosted environments, such as self-hosted apps or headless projects. The client manages authentication and provides access to the SDK modules you specify.

When you need a client

You need to create a Wix client in these environments:

You don't need to create a client if you are developing in these Wix-hosted environments:

In these cases, you can call the SDK's APIs directly and authentication is handled automatically.

Create a client

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

Authorization strategies (auth)

The correct strategy depends on your context and the identity you want to use. To learn more about identities, see About Identities.

The following strategies are available:

  • AppStrategy: For Wix apps. Requires app credentials and instance ID.
  • OAuthStrategy: For visitors or members in headless projects. Requires a client ID and tokens.
  • ApiKeyStrategy: Use for admin access in headless, channel, or enterprise contexts. Requires an API key and site or account ID.
    • Host module auth: For dashboard, editor, and site pages in Wix apps. Auth is handled by the host module.

The strategy you should use depends on your context:

ContextIdentityStrategy
Wix app (backend extension)App, Visitor, MemberAppStrategy
Wix app (dashboard page)Wix userHost module auth
Wix app (editor/site page)Visitor, MemberHost module auth
Headless site or appVisitor, MemberOAuthStrategy
Headless site or appAdminApiKeyStrategy
Wix Channel/Enterprise appAdminApiKeyStrategy

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() method to specify the host when creating a client.
    • When working in a non-hosted context, such as your app backend, don't specify a host when creating a client.
  • In Headless sites and apps, you never need to specify a host when creating a client.
  • In apps created with the Wix CLI, you don't use a client, so you never need to specify a host.

Each hosted context has its own host module. The host modules are:

  • dashboard
  • editor
  • site

SDK modules (modules)

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

Code examples

The following code examples show how to create a client in different contexts and with different authorization strategies.

Headless as a visitor (OAuthStrategy)

Copy

Headless as admin (ApiKeyStrategy)

Copy

Wix app as app (AppStrategy)

Copy

Wix app as a Wix user (dashboard host)

Copy

Wix app as visitor/member (editor host)

Copy

See also

Did this help?