After you create an OAuth app for your client site or app in your project dashboard, you can begin coding by installing the Wix JavaScript SDK, importing modules in your code, and creating an SDK client.
Note: Before you start, make sure you are using Node.js version 18 or higher.
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:
or
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:
Make sure to import both createClient
and OAuthStrategy
from @wix/sdk
.
To get started connecting to a Wix project, use the createClient()
function imported from the @wix/sdk
package to create a new client.
For example:
Pass the modules you want to use and authorization information when creating the client.
modules
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.auth
property contains the authentication method and credentials for connecting with your Wix project. To use the OAuth authentication strategy, call OAuthStrategy()
with an object containing:
clientId
: Your OAuth app client ID. You can retrieve it from the Headless Settings menu in the dashboard. If you haven't created an OAuth app yet, see Create an OAuth App to set one up.tokens
: Optional. An object containing access and refresh tokens for a site visitor or member. If you pass tokens, every call made by the client uses these tokens to maintain a persistent session.After creating a client, you can use it to call APIs.
For example:
Often, you will need to maintain a persistent session to work with site or app visitors and members. Sessions are maintained using tokens. Most of the token management is handled by the client object, but there is some work you need to do, which differs depending on your situation.