> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: About the Wix Client

## Article: About the Wix Client

## Article Link: https://dev.wix.com/docs/sdk/articles/set-up-a-client/about-the-wix-client.md

## Article Content:

# About the Wix Client

Use a Wix client to make authenticated calls to the [Wix JavaScript SDK](https://dev.wix.com/docs/sdk.md) from a self-managed environment.

## When you need a Wix client

You need to create a Wix client when developing the following:

+ [Self-managed Wix apps](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/self-hosting/about-self-hosting-for-wix-apps.md)
+ [Self-managed headless projects](https://dev.wix.com/docs/go-headless/get-started/about-headless/headless-development-paths.md#self-managed-headless)

## When you don't need a Wix client

You **don't** need to create a Wix client if you are working in the following Wix-managed environments:

+ [Environments for extending Wix sites](https://dev.wix.com/docs/develop-websites/articles/get-started/development-environments.md)
+ Wix CLI app projects:
    - [Wix CLI for Apps](https://dev.wix.com/docs/wix-cli/cli-for-apps/about-the-wix-cli-for-apps.md)
    - [Astro-based Wix CLI for Apps](https://dev.wix.com/docs/wix-cli/legacy-clis/astro-based-wix-cli-for-apps/about-the-astro-based-wix-cli-for-apps.md)
    - [Legacy Wix CLI for Apps](https://dev.wix.com/docs/wix-cli/legacy-clis/legacy-wix-cli-for-apps/about-the-legacy-wix-cli-for-apps.md)
+ [Wix Blocks](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-blocks/about-wix-blocks.md)
+ [Wix-managed headless projects built with Astro](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/about-the-astro-integration.md)
  
In these cases you can call the JavaScript SDK's APIs directly and authentication is taken care of for you automatically.

## Create a client

In cases where you need to create a client, call the [`createClient()`](https://dev.wix.com/docs/sdk/core-modules/sdk/wix-client.md#createclient) function and provide values for the following parameters:

  - `auth`: The [authorization strategy](#authorization-strategy-auth) used to authorize your calls to the SDK. 
  - `host`: The [host](#hosted-context-host), when calling the SDK from a hosted context, such as the dashboard or editor.
  - `modules`: The [SDK modules](#sdk-modules-modules) you want to call using this client.

Refer to the [examples](#examples) below to see how to create a client using these parameters for a number of different scenarios.

## Authorization strategy (`auth`)

There are a number of different authorization strategies you can use with the `auth` parameter. 

The correct strategy to use depends on:

- The [context](https://dev.wix.com/docs/sdk/articles/set-up-a-client/authorization-strategies.md#context) in which you are making API calls. For example, whether you are calling the SDK from a Headless site or a Wix app.
- The [identity](https://dev.wix.com/docs/overview/auth-permissions/identities.md) you are using to call the API. For example, whether you are calling the SDK as a site visitor or as Wix app. Note that each function in the SDK can only be called by the identities specified in the SDK reference. 

The following table outlines the supported authorization strategies, the cases they apply to, and the parameters needed to create the strategies:
| Auth strategy                                                                      | Supported Contexts                                                                                                                    | Identities                                                                                                                                                                                                   | Parameters                                                                                                                                                                                                                                                                                                                                        |
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`OAuthStrategy`](https://dev.wix.com/docs/sdk/core-modules/sdk/oauth-strategy.md)    | Headless site or app                                                                                                                      | Site visitor, site member                                                                                                                                                                                    | [Client ID](https://dev.wix.com/docs/sdk/core-modules/sdk/oauth-strategy.md#parameters), Tokens (when [resuming a session](https://dev.wix.com/docs/go-headless/authentication/visitors/about-visitor-authentication.md))                                                                                                                                                                         |
| [`AppStrategy`](https://dev.wix.com/docs/sdk/core-modules/sdk/app-strategy.md)        | Wix app ([backend extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/about-extensions.md#backend-extensions))   | Wix app, Wix user (when using [elevation](https://dev.wix.com/docs/overview/auth-permissions/elevation.md)), site visitor or site member (when passing an access token from the frontend) | app ID, app secret, app instance ID (when authenticating with the Wix app identity), App public key (when using webhooks or [service plugins](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/service-plugins/about-service-plugin-extensions.md)), Tokens (when authenticating as a site visitor or site member) |
| [`ApiKeyStrategy`](https://dev.wix.com/docs/sdk/core-modules/sdk/api-key-strategy.md) | Headless site or app, Wix app                                                                                                             | API key                                                                                                                                                                                                      | API Key                                                                                                                                                                                                                                                                                                                                           |
| [Host module auth](#host-module-auth)                                              | Wix app ([frontend extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/about-extensions.md#frontend-extensions)) | Site visitor, site member, Wix user                                                                                                                                                                          | -                                                                                                                                                                                                                                                                                                                                                 |

### Host module auth
When creating a client within a [hosted context](#hosted-context-host), such as the dashboard or the editor, use the host's specific authorization strategy by calling the host module's `auth()` function. For example, `dashboard.auth()`. 

If you are only calling frontend modules from the editor or site, you can omit the authentication altogether.

The identity used by a client created with a host authorization strategy depends on which host is being used. Within the dashboard, the identity is Wix user. In the editor or site, the identity is site visitor or site member.

## Hosted context (`host`)

Depending on the context in which you are making API calls, you may need to specify a `host`.

- In [self-managed apps](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/self-hosting/about-self-hosting-for-wix-apps.md): 
  - When working in a hosted context, such as the dashboard or editor, use the relevant host module's `host()` function to specify the host when creating a client. 
  - When working in a non-hosted context, such as your app backend, do not specify a `host` when creating a client. 
- In Headless sites and apps, you never need to specify a `host` when creating a client.
- In apps created with the Wix CLI, you don't use a client, so you never need to specify a `host`.

Each hosted context has its own host module. The host modules are:
- [`dashboard`](https://dev.wix.com/docs/sdk/host-modules/dashboard/introduction.md)
- [`editor`](https://dev.wix.com/docs/sdk/host-modules/editor/introduction.md)
- [`site`](https://dev.wix.com/docs/sdk/host-modules/site/introduction.md)

## SDK Modules (`modules`)

In all cases, when creating a client, you need to specify which SDK modules you will call using that client. Simply list the imported modules you want to call.

## Examples

### Headless as a visitor

Create a client to call Bookings Services APIs as a site visitor using the `OAuthStrategy` for a Headless project.

You can find your client ID in the [**Headless Settings**](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Foauth-apps-settings) of your project dashboard.

```js
import { createClient, OAuthStrategy } from "@wix/sdk";
import { services } from "@wix/bookings";

//...

const myWixClient = createClient({
    auth: OAuthStrategy({
      clientId: "<YOUR_CLIENT_ID>",
    }),
    modules: {
      services
    }
});

//...

const { items } = await myWixClient.services.queryServices({});
```

### Wix app as a Wix app

Create a client to call Bookings Services APIs as the Wix app identity using the `AppStrategy` for a Wix app:

```js
import { createClient, AppStrategy } from "@wix/sdk";
import { services } from "@wix/bookings";

//...

const myWixClient = createClient({  
  auth: AppStrategy({
    appId: "<YOUR_APP_ID>",
    appSecret: "<YOUR_APP_SECRET>",
    instanceId: "<APP_INSTANCE_ID>"
  }),
  modules: {
    services
  }
});

//...

const { items } = await myWixClient.bookings.queryBookings({});
```

### Wix app as a Wix user in the dashboard

Create a client to call Bookings Services and Dashboard APIs as a Wix user using the dashboard host for a Wix app:

```js
import { createClient } from "@wix/sdk";
import { dashboard } from "@wix/dashboard";
import { services } from "@wix/bookings";

//...

const myWixClient = createClient({
  host: dashboard.host(),
  auth: dashboard.auth(),
  modules: {
    dashboard,
    services
  }
});

//...

const { items } = await myWixClient.bookings.queryBookings({});

dashboard.showToast({
  message: "This is a toast!",
  type: "success",
});
```

### Wix app as a site visitor or member in the editor (or site)

Create a client to call Bookings Services and Editor APIs as a site visitor or member using the editor host for a Wix app:

```js
import { createClient } from "@wix/sdk";
import { editor, info } from "@wix/editor";
import { services } from "@wix/bookings";

//...

const myWixClient = createClient({
  host: editor.host(),
  auth: editor.auth(),
  modules: {
    info,
    services
  }
}); 

//...

const { items } = await myWixClient.bookings.queryBookings({});

const languageCode = await client.info.getLanguageCode();
```

### Wix app as a visitor or member in the backend

Call Bookings Services APIs as a site visitor or member in the backend of a Wix app. To do so, you need to pass a visitor or member access token from the frontend:

```js
// Frontend code

const result = await fetchWithAuth('https://my-backend.com/api/func');
```

```js
// Backend code

import { services } from "@wix/bookings";
import { createClient, AppStrategy } from '@wix/sdk';

app.get('/func', async (req, res) => {
  const accessToken = req.headers['Authorization'];

  const myWixClient = createClient({
    auth: AppStrategy({
      appId: "<YOUR_APP_ID>",
      appSecret: "<YOUR_APP_SECRET>",
      accessToken
    }),
    modules: {
      services
    }
  });

  
  const { items } = await myWixClient.bookings.queryBookings({});

  res.send({});
});

```

### Headless or Wix app using an API Key

Create a client to call Bookings Services APIs using the `ApiKeyStrategy` for a Headless site or Wix app:

```js
import { createClient, ApiKeyStrategy } from "@wix/sdk";
import { services } from "@wix/bookings";

//...

const myWixClient = createClient({
  auth: ApiKeyStrategy({
    apiKey: "<YOUR_API_KEY>",
  }),
  modules: {
    services
  }
});

//...

const { items } = await myWixClient.services.queryServices({});
```