> 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: ApiKeyStrategy

## Article: ApiKeyStrategy

## Article Link: https://dev.wix.com/docs/sdk/core-modules/sdk/api-key-strategy.md

## Article Content:

# ApiKeyStrategy

<blockquote class="important">

**Important:** This strategy is for administrative operations at the site or account level. For security purposes, a request made from the browser using an API key will encounter errors attributed to cross-origin resource sharing (CORS) restrictions. To learn more, see [Authorization Strategies](https://dev.wix.com/docs/sdk/articles/set-up-a-client/authorization-strategies.md).

</blockquote>

This authentication strategy is used along with a [`Wix Client`](https://dev.wix.com/docs/sdk/core-modules/sdk/wix-client.md) to authenticate API calls using an API Key.

When using this authentication strategy for an API request, the requester's identity is that of the corresponding [API Key](invalid-url). The permissions associated with this API Key are set in the Dev Center.

## ApiKeyStrategy()

Creates an authentication strategy object that uses an API key.

#### Syntax

```js
ApiKeyStrategy({apiKey: string, accountId: string, siteId: string}): ApiKeyStrategy
```

#### Parameters

| Name | Type | Description |
|:-|:-|:-|
| `apiKey` | string | The API key to use for authentication. |
| `accountId` | string | **Optional.** The account ID to use for authentication when calling account-level APIs. |
| `siteId` | string | **Optional.** The site ID to use for authentication when calling site-level APIs. |

> **Note:**
> You must provide either a `siteId` or `accountId` value, depending on whether you're calling site-level or account-level functionality. To learn how to retrieve these values, see [Site and Account IDs](https://dev.wix.com/docs/sdk/articles/set-up-a-client/authorization-strategies.md).

#### Returns

`ApiKeyStrategy`

## Functions

### setAccountId()

Sets the account ID to use along with an API Key when authenticating. 

Use an account ID for authentication when you need to call account-level APIs.

Set the `accountId` to `undefined` and use the `setSiteId()` function to set a `siteId` if you want to use an API key to call site-level APIs.

#### Syntax

```js
setAccountId(accountId: string): void
```

#### Parameters

| Name        | Type   | Description                                       |
| :---------- | :----- | :------------------------------------------------ |
| `accountId` | string | ID of the Wix account to use when authenticating. |

### setSiteId()

Sets the site ID to use along with an API Key when authenticating.

Use a site ID for authentication when you need to call site-level APIs.

Set the `siteId` to `undefined` and use the `setAccountId()` function to set an `accountId` if you want to use an API key to call account-level APIs.

#### Syntax

```js
setSiteId(siteId: string): void
```

#### Parameters

| Name     | Type   | Description                                       |
| :------- | :----- | :------------------------------------------------ |
| `siteId` | string | ID of the Wix account to use when authenticating. |

## Example

The following code creates a client that can make requests to the coupons module using the API key strategy. The site ID is for providing site-level operations. To perform account-level operations, include the account ID instead of the site ID. 

```js
import { createClient, ApiKeyStrategy } from '@wix/sdk';
import { coupons } from "@wix/marketing";

const myClient = createClient({
  modules: { coupons },
  auth: ApiKeyStrategy({
    apiKey: '<API_KEY>',
    siteId: '<SITE_ID>'
  })
});

const couponId = "058b0b56-e90d-4f4e-a8a3-8bf90b3fc4e6"
const response = await wixClient.coupons.deleteCoupon(couponId);
```