A Wix Client is used to call functionality from the Wix JavaScript SDK. APIs from the SDK's modules, such as bookings
and ecom
, are called using the API Client. The client also manages the authentication of SDK calls.
In self-hosted apps you need to initialize and use the client yourself.
Note: In Wix-hosted apps created with the Wix CLI or Wix Blocks, the Wix native frameworks can initialize and use the client for you. You do not need to create a client.
Creates a client instance with a designated authentication strategy, such as OAuthStrategy
, AppStrategy
, or ApiKeyStrategy
. For guidance on selecting the appropriate strategy, see Authorization Strategies.
Name | Type | Description |
---|---|---|
config | ClientConfig | Client configuration. |
Name | Type | Description |
---|---|---|
modules | object | SDK modules to initialize for use with this client. |
auth | AuthenticationStrategy | Authentication strategy to use for authenticating API calls, such as OAuthStrategy , AppStrategy , or APIKeyStrategy . |
headers | Headers | Headers for client calls. Can be used to set alternative authentication credentials such as authorization tokens used when creating a client to be used in a Wix App. |
host | Host | An API host. You only need to set a host when using a client to call hosted modules, such as the dashboard module. |
WixClient
An instance of WixClient
contains the following properties:
The client's authentication strategy, such as OAuthStrategy
, AppStrategy
, or ApiKeyStrategy
.
Use to handle events.
Tip: To learn how work to work with events using a WixClient
, see Handle Events With Webhooks.
The webhooks
property offers the following methods and subproperties:
Processes a webhook event represented by a JSON Web Token (JWT). This method verifies the JWT signature and payload, ensuring event authenticity.
Returns a promise that resolves after all registered handlers for the incoming webhook type are executed. If any of the handlers fail, the promise is rejected.
For an example, see Handle Events With Webhooks.
An extension of the .process()
function that accepts a standard WebRequest
instance, instead of the plain body object. This simplifies invocation by integrating with standard web request objects.
Offers access to the following specific app-related events:
appId
of the installed app and the originInstanceId
associated with the installation.appId
.The following functions are available once you have a WixClient
instance.
Fetch a resource from the Wix REST API using the client's authentication.
Warning: The fetch()
function is deprecated in favor of fetchWithAuth()
.
Name | Type | Description |
---|---|---|
relativeUrl | string | URL of the Wix REST API to call. |
options | RequestInit | Request options. |
Response - Standard fetch()
response.
Use to make requests to both the Wix REST API and external endpoints that require a Wix access token. The access token is generated using authentication details provided to the client and is automatically included in requests as an Authorization
header.
Notes:
fetchWithAuth()
from the essentials
module instead.Name | Type | Description |
---|---|---|
relativeUrl | string | URL of the Wix REST API to call. |
options | RequestInit | Request options. |
Response - Standard fetch()
response.
Sets headers for the client.
You can use the setHeaders()
function to set headers such as an authorization header to be used for authentication when using the Wix JavaScript SDK from a Wix App.
Name | Type | Description |
---|---|---|
headers | Record<string, string> | Header information. |
Binds an SDK module with the client's authentication strategy and returns an initialized module.
Name | Type | Description |
---|---|---|
modules | Module | An SDK module to bind with the client's authentication strategy. |
InitializedModule
- An initialized module bound to the client's authentication strategy.
Calls Wix APIs through the Wix GraphQL API.
Supports queries and mutation.
The Wix GraphQL API is in Alpha and is subject to change.
Name | Type | Description |
---|---|---|
query | TypedQueryInput<Result, Variables> | Wix GraphQL query to execute. |
variables | object | Variables to use in the query. Optional. |
Name | Type | Description |
---|---|---|
data | object | Result of the query. The format of the data depends on the query. |
errors | object | GraphQL query errors. This property is not returned if there are no errors. |
Query products using graphQL: