Wix Client

Use a Wix client to make authenticated calls to the Wix JavaScript SDK from a self-hosted environment.

When you need a Wix client

You need to create a Wix client in the following environments:

When you don't need a Wix client

You don't need to create a Wix client if you are developing a Wix site or app in the following Wix-hosted environments:

In these cases you can call the JavaScript SDK's APIs directly and authentication is taken care of for you automatically.

createClient()

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.

Syntax

Copy

Parameters

NameTypeDescription
configClientConfigClient configuration.
ClientConfig
NameTypeDescription
modulesobjectSDK modules to initialize for use with this client.
authAuthenticationStrategyAuthentication strategy for API calls, such as OAuthStrategy, APIKeyStrategy, or AppStrategy. However, for apps running in Wix frontend environments like the dashboard, editor, or site, authentication is handled automatically. In these cases, you typically pass an environment-specific host reference such as auth: dashboard(). For more details, see About Host Modules.
headersHeadersHeaders 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.
hostHostAn API host. You only need to specify host when using a client to make requests from a Wix-hosted frontend, such as the dashboard, site, or editor. For more information, see About Host Modules.

Returns

WixClient

Properties

An instance of WixClient contains the following properties:

auth

The client's authentication strategy, such as OAuthStrategy, AppStrategy, or ApiKeyStrategy.

webhooks

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:

process()

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.

processRequest()

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.

apps

Offers access to the following specific app-related events:

  • AppInstalled: Triggered when an app is installed. Provides details such as the appId of the installed app and the originInstanceId associated with the installation.
  • AppRemoved: Triggered when an app is removed. Provides details about the removed app, including its appId.

Functions

The following functions are available once you have a WixClient instance.

fetch() (Deprecated)

Fetch a resource from the Wix REST API using the client's authentication.

Warning: The fetch() function is deprecated in favor of fetchWithAuth().

Syntax

Copy

Parameters

NameTypeDescription
relativeUrlstringURL of the Wix REST API to call.
optionsRequestInitRequest options.

Returns

Response - Standard fetch() response.

fetchWithAuth()

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:

Syntax

Copy

Parameters

NameTypeDescription
relativeUrlstringURL of the Wix REST API to call.
optionsRequestInitRequest options.

Returns

Response - Standard fetch() response.

setHeaders()

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.

Syntax

Copy

Parameters

NameTypeDescription
headersRecord<string, string>Header information.

use()

Binds an SDK module with the client's authentication strategy and returns an initialized module.

Syntax

Copy

Parameters

NameTypeDescription
modulesModuleAn SDK module to bind with the client's authentication strategy.

Returns

InitializedModule - An initialized module bound to the client's authentication strategy.

Example

Copy

graphql()

Calls Wix APIs through the Wix GraphQL API.

Supports queries and mutation.

Important:

The Wix GraphQL API is in Alpha and is subject to change.

Syntax

Copy

Parameters

NameTypeDescription
queryTypedQueryInput<Result, Variables>Wix GraphQL query to execute.
variablesobjectVariables to use in the query. Optional.

Returns

NameTypeDescription
dataobjectResult of the query. The format of the data depends on the query.
errorsobjectGraphQL query errors. This property is not returned if there are no errors.

Example

Query products using graphQL:

Copy
Did this help?