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.
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.
In cases where you need to create a client, call the createClient()
method and provide values for:
auth
: The authorization strategy for your calls.host
: The host, which is only needed in some hosted contexts, like dashboard or editor.modules
: The SDK modules you want to use.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:
The strategy you should use depends on your context:
Context | Identity | Strategy |
---|---|---|
Wix app (backend extension) | App, Visitor, Member | AppStrategy |
Wix app (dashboard page) | Wix user | Host module auth |
Wix app (editor/site page) | Visitor, Member | Host module auth |
Headless site or app | Visitor, Member | OAuthStrategy |
Headless site or app | Admin | ApiKeyStrategy |
Wix Channel/Enterprise app | Admin | ApiKeyStrategy |
host
)Depending on the context in which you are making API calls, you may need to specify a host
.
host()
method to specify the host when creating a client.host
when creating a client.host
when creating a client.host
.Each hosted context has its own host module. The host modules are:
dashboard
editor
site
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.
The following code examples show how to create a client in different contexts and with different authorization strategies.
OAuthStrategy
)ApiKeyStrategy
)AppStrategy
)