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

## Article: Introduction

## Article Link: https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/introduction.md

## Article Content:

# About the Campaign API

With the Campaign API you can create and manage email marketing campaigns for a Wix site, including composing content, publishing to contacts, and tracking engagement statistics.

With the Campaign API, you can:

- [Create](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/create.md) campaigns from editor data.
- [Retrieve](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/get-campaign.md) information about a campaign.
- [List](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/list-campaigns.md) all campaigns for a site.
- [Publish](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/publish-campaign.md) a campaign and send it to contacts.
- Send a [test email](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/send-test.md) to preview how a campaign will look in an inbox.
- [Reschedule](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/reschedule.md) a scheduled campaign.
- [Resend](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/resend-to-non-openers.md) a campaign to recipients who didn't open the original email.
- [Reuse](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/reuse-campaign.md) an existing campaign to create a draft copy.
- Retrieve [statistics](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/list-statistics.md) and [recipients](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/list-recipients.md) for a campaign. Statistics are available only for published campaigns.

## Creating a campaign

Use [Create Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/create.md) to create a new draft campaign from editor data. Pass the `composerDataJson` field with the campaign's content and set `campaignEditorType` to match the format you're using.

The `composerDataJson` field supports four formats, determined by `campaignEditorType`:

- `WEB`: Wix proprietary JSON format for the classic drag-and-drop editor.
- `MOBILE`: A subset of the `WEB` format for the classic mobile editor.
- `MJML`: MJML markup wrapped in a JSON object under key "mjml".
- `HTML`: Raw HTML wrapped in a JSON object under key "html".

Passing a format that doesn't match the specified `campaignEditorType` doesn't return an immediate error, but causes the campaign to fail silently when previewing or sending. `MJML` or `HTML` are the most straightforward formats to generate programmatically.

If you plan to open MJML content in AI Composer, check the [supported components and limitations](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/update-composer.md) first. For example, opening `<mj-table>` in AI Composer removes its rows.

You can also set an optional `emailPreheader` when creating or updating a campaign. This is short preview text shown after the subject line in many email clients and can improve open rates.

After creating a campaign, you can update its content with [Update Composer](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/update-composer.md) or render a preview with [Preview Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/preview.md).

The `campaignEditorType` can't be changed after a campaign is created. Passing a `composerDataJson` in a different format when calling Update Composer causes a silent failure when sending or previewing.

If your campaign content contains dynamic placeholders for personalization, pass a `placeholders` map to [Preview Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/preview.md) to resolve those tokens in the preview. Set default placeholder values in `composer.defaultValues` to use as fallbacks when actual recipient values aren't available.

To retrieve a campaign's subject line, use [Get Composer](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/get-composer.md). The `emailSubject` field on the [Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/campaign-object.md) object is deprecated.

## Publishing a campaign

To publish a campaign, sender details must be set up for the site. Call [Identify Sender Address](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/identify-sender-address.md) to determine which email address will appear as the "From" address.

Call [Publish Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/publish-campaign.md) to send the campaign:

- Pass `emailDistributionOptions` to distribute the campaign by email to contacts. Campaigns can only be sent to Wix site contacts, defined by contact IDs, contact labels, or segment IDs.
- Omit `emailDistributionOptions` to publish the campaign as a landing page only, without sending any emails. This decision is permanent — once published as a landing page only, the campaign can't be sent by email. Use [Reuse Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/reuse-campaign.md) to create a new draft copy if you need to send emails later.

The response always includes a `landingPageUrl` that can be shared on social media, regardless of whether emails are sent.

You can schedule a campaign to send at a future time by passing `emailDistributionOptions.sendAt`. The scheduled time must be at least 30 minutes and at most 1 year in the future. Use [Pause Scheduling](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/pause-scheduling.md) and [Reschedule](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/reschedule.md) to adjust a scheduled campaign before it sends.

## Email distribution process

After publishing with email distribution, the campaign moves through the following `distributionStatus` values:

1. `SAMPLING`: A small subset of the audience receives the email first. The system checks for issues such as spam-trap hits or excessive bounce rates.
2. `SENDING`: Sampling passed and the email is being sent to the full audience.
3. `DISTRIBUTED`: The email has been sent to all recipients.
4. `TERMINATED`: Sampling failed due to quality issues. The campaign is stopped before reaching the full audience. A terminated campaign can be reused with [Reuse Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/reuse-campaign.md) to create a new draft for republishing.
5. `REJECTED`: The campaign was identified as abusive and blocked before sending.

## Paused campaigns and audience retrieval

When a scheduled campaign is paused with [Pause Scheduling](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/pause-scheduling.md), the original audience settings are preserved. Use [Get Audience](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/get-audience.md) to retrieve those audience settings so you can pass them back when republishing the campaign.

## Resending to non-openers

Use [Resend to Non-Openers](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/resend-to-non-openers.md) to send a follow-up to recipients who didn't open the original campaign email. The following conditions must be met:

- The original campaign was sent at least 24 hours ago.
- There are recipients who received the email but didn't open it.
- Resend to Non-Openers hasn't already been called for this campaign.

An optional different subject line can be passed to improve open rates on the follow-up.

## Before you begin

It's important to note the following points before starting to code:

- Each site has an email quota per billing period that depends on the [email marketing plan](https://support.wix.com/en/article/email-marketing-upgrading-your-email-marketing-plan).
- The site's email marketing account must be active. A site owner can be blocked from using email marketing for not complying with the [Wix Email Marketing Terms of Use](https://www.wix.com/shoutout/terms-of-use). Use [Get Account Details](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/account-details/get-account-details.md) to check the account status before publishing.
- Sender details must be configured before publishing a campaign.
- Campaigns can only be sent to Wix site [contacts](https://dev.wix.com/docs/rest/crm/members-contacts/contacts/contacts/contact-v4/introduction.md).

## Use cases

- [A/B test email subject lines](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/sample-use-cases-and-flows.md)

## Terminology

- **Campaign:** A marketing message distributed to an audience via email and a public landing page.
- **Composer:** The editor data for a campaign, containing the email content in `composerDataJson` and the email subject.
- **Campaign editor type:** Determines the format of `composerDataJson`. Options are `WEB`, `MOBILE`, `MJML` and `HTML`.
- **Preheader:** Short preview text shown after the subject line in many email clients. Set via `emailPreheader` on [Create Campaign](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/create.md) or [Update Composer](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/update-composer.md).
- **Sampling:** The initial phase of email distribution where a small subset of recipients receive the email first, before it's sent to the full audience.
- **Audience:** The group of recipients targeted by a campaign, defined by contact IDs, contact labels, or segment IDs.
- **Campaign scheduling:** Setting a future date and time for a campaign to be sent. Requires at least 30 minutes' notice and a plan that supports scheduling.
- **Label:** A tag used to organize and group site contacts, which can be used to define a campaign audience.
- **Landing page:** A public web page generated for each published campaign. Available regardless of whether the campaign is distributed by email.

## SDK Setup
  `@wix/email-marketing`

To use the API, install the `@wix/email-marketing` package.

#### Install the package

Follow the installation instructions for your development environment.

| Development environment | Installation method |
|--|--|
| Wix sites (editor or IDE) | Use the [package manager](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/packages/work-with-npm-packages-in-the-editor.md). |
| Wix sites (local IDE) | Run `wix install @wix/email-marketing` using the [Wix CLI](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/packages/work-with-npm-packages-with-the-wix-cli.md).|
| Blocks apps | Use the same installation method as Wix sites. |
| CLI and self-hosted apps | Run `npm install @wix/email-marketing` or `yarn add @wix/email-marketing`. |
| Headless sites and apps | Run `npm install @wix/email-marketing` or `yarn add @wix/email-marketing`. |

#### Import the package

To import the package in your code:

```js
import { campaigns } from '@wix/email-marketing'
```

#### Import types

Types for this API are accessed through the `campaigns` namespace you already imported above, as `campaigns.<TypeName>`, using any type name shown in these docs.
  