Create a Client with an API Key

Share your feedback
Reach out to us with feedback and suggestions to improve the Wix Headless experience, and join the Headless channel of the Devs on Wix Discord community to discuss features and connect with our growing community of developers.

Once you have generated an API key and obtained the IDs for your Wix account and Wix site, you can use them to create an SDK client that uses your API key to authenticate.

Prerequisites

Note: Before you start, make sure you are using Node.js version 18 or higher.

Install packages

Install @wix/sdk and the packages for the domain-specific APIs you wish to work with. Domain-specific packages follow the naming convention @wix/{domain}. For example:

Copy
1

or

Copy
1

Import modules

To use the APIs you have installed, import createClient from the @wix/sdk package along with an authentication strategy, and import functionality from the desired domain-specific packages you installed. For example:

Copy
1

Create a client

To get started connecting an external client with a Wix site, use the createClient() function imported from the @wix/sdk package.

Copy
1

The createClient() function returns a new Wix client.

  • The modules parameter property contains key:value pairs. Each value is an imported module you wish to enable in the client, and the key defines the name to use for working with that module.
  • The auth parameter property contains the authentication method and credentials for connecting with your Wix project. To create a client for your Wix project, pass ApiKeyStrategy() with an object containing:
    • apiKey: An API key that you generated in the API Key Manager.
    • siteId: ID of the Wix site or project you are working with. Required for site-level API calls.
    • accountId: ID of the Wix account the API key belongs to. Required for account-level API calls.

Once you have created a client successfully, you can begin using it to call functions in the API Reference.

Example

Copy
1
Was this helpful?
Yes
No