> 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`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Create

# Package: emailMarketing

# Namespace: CampaignService

# Method link: https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/create.md

## Permission Scopes:
Manage Email Marketing: SCOPE.DC-PROMOTE.EMAIL-MARKETING

## Introduction

Creates a new email marketing campaign from editor data.

The campaign is created as a draft. Call [Publish](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/publish.md) to send it to recipients.

---

## REST API

### Schema

```
 Method: create
 Description: Creates a new email marketing campaign from editor data.  The campaign is created as a draft. Call [Publish](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/publish.md) to send it to recipients.
 URL: https://www.wixapis.com/email-marketing/v1/campaigns
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  composer, composer.composerDataJson
 Method parameters: 
   param name: campaignEditorType | type: CampaignEditorType | description: Editor type.  
        - name: value | type: Enum | description:   
             - enum:
             -     UNKNOWN: Unknown editor. This value isn't used.
             -     WEB: Wix classic drag-and-drop email editor. The `composerDataJson` is stored in Wix proprietary JSON format.
             -     MOBILE: Wix classic mobile-optimized email editor. The `composerDataJson` is stored in a subset of the `WEB` format.
             -     MJML: AI-powered email editor. The `composerDataJson` is stored in MJML format wrapped in JSON.
   param name: composer | type: Composer | description: Represents a campaign's editor data that is used to render the campaign in the editor and viewer. | required: true 
        - name: composerDataJson | type: string | description: Editor content for the campaign. The format depends on `campaignEditorType`:  - `WEB`: Wix proprietary JSON format used by the drag-and-drop email editor. - `MOBILE`: A subset of the `WEB` format, used by the mobile email editor. - `MJML`: MJML markup wrapped in a JSON object under key "mjml".  Passing the wrong format for the given `campaignEditorType` causes a silent failure when sending or previewing the campaign. | required: true | validation: maxLength 10000000
        - name: defaultValues | type: DefaultValues | description: Fallback values for dynamic placeholders in the campaign content.  
           - name: map | type: object | description: Map of placeholder keys to their default values.  | validation: maxItems 500, format map
   param name: emailPreheader | type: emailPreheader | description: Short preview text shown after the subject line in some email clients (optional).  | validation: maxLength 1000
   param name: emailSubject | type: emailSubject | description: Subject line displayed in recipients' inboxes (optional).  | validation: maxLength 1000
 Return type: CreateCampaignResponse
  - name: campaign | type: Campaign | description: Campaign information.  
     - name: campaignId | type: string | description: Campaign GUID.  | validation: format GUID
     - name: title | type: string | description: Campaign title. Used to identify the campaign in the dashboard. Defaults to the email subject if not provided.  
     - name: firstImageUrl | type: string | description: URL of the first image after the logo.  | validation: format WEB_URL
     - name: editorType | type: Enum | description: Editor type that determines the format of `composerDataJson`.  
         - enum:
         -     UNKNOWN: Unknown editor. This value isn't used.
         -     WEB: Wix classic drag-and-drop email editor. The `composerDataJson` is stored in Wix proprietary JSON format.
         -     MOBILE: Wix classic mobile-optimized email editor. The `composerDataJson` is stored in a subset of the `WEB` format.
         -     MJML: AI-powered email editor. The `composerDataJson` is stored in MJML format wrapped in JSON.
     - name: status | type: Enum | description: Campaign status.  
         - enum:
         -     UNKNOWN: Unknown campaign. This value isn't used.
         -     ACTIVE: Campaign is active.
         -     ARCHIVED: Campaign is archived.
         -     DELETED: Campaign is deleted.
     - name: visibilityStatus | type: Enum | description: Whether the campaign is a draft, published, or a template.  
         - enum:
         -     UNKNOWN: Unknown status. This value isn't used.
         -     DRAFT: Campaign isn't published yet.
         -     PUBLISHED: Campaign is published.
         -     TEMPLATE: Campaign is a template.
     - name: distributionStatus | type: Enum | description: Campaign distribution status.  
         - enum:
         -     UNKNOWN: Unknown distribution status.
         -     NOT_STARTED: Campaign isn't distributed to recipients yet.
         -     SCHEDULED: Campaign is scheduled for distribution.
         -     IN_DETECTION: Campaign is in screening for malicious content.
         -     IN_MODERATION: Campaign is in review by the site moderators.
         -     SAMPLING: A subset of recipients receives the campaign first to check for deliverability issues before sending to the full audience.
         -     SENDING: Campaign is being sent out to all recipients.
         -     REJECTED: Campaign was identified as abusive and rejected before sending.
         -     TERMINATED: Campaign is terminated after a failed sampling test.
         -     DISTRIBUTED: Campaign is fully distributed to all recipients.
         -     PAUSED: Scheduled campaign is paused.
     - name: publishingData | type: PublishingData | description: Publishing data. The field is returned empty if the campaign isn't published.  
        - name: landingPageUrl | type: string | description: Landing page URL.  | validation: format WEB_URL
        - name: statistics | type: CampaignStatistics | description: Campaign engagement statistics.  
           - name: landingPage | type: LandingPageStatistics | description: Landing page statistics.  
              - name: opened | type: integer | description: Number of times the landing page was loaded or viewed.  
              - name: clicked | type: integer | description: Number of times a link was clicked in a landing page.  
           - name: emailCampaign | type: DistributionStatistics | description: Email distribution statistics.  
              - name: delivered | type: integer | description: Number of delivered emails.  
              - name: opened | type: integer | description: Number of recipients who opened an email.  If the same recipient opened the same email twice, it is counted as a one unique open.  
              - name: clicked | type: integer | description: Number of recipients who clicked a link in the email.  If the same recipient clicked the same link twice, it is counted as a one unique click.  If the same recipient clicked different links, it is counted as a one unique click.  
              - name: bounced | type: integer | description: Number of emails that didn't reach the recipient.  
              - name: complained | type: integer | description: Number of recipients who reported the email as spam.  
              - name: notSent | type: integer | description: Number of emails that weren't sent due to campaign termination.  
           - name: total | type: TotalStatistics | description: Combined statistics of landing page and email distribution.  
              - name: mailsSent | type: integer | description: Total number of emails sent.  
              - name: opened | type: integer | description: Number of landing page views and opened emails.  
              - name: clicked | type: integer | description: Number of landing page and email link clicks.  
        - name: datePublished | type: string | description: Date and time the campaign was published.  | validation: format date-time
        - name: wasResentToNonOpeners | type: boolean | description: Whether the campaign was resent to recipients who didn't open the original email.  
     - name: dateCreated | type: string | description: Date and time the campaign was created.  | validation: format date-time
     - name: dateUpdated | type: string | description: Date and time the campaign was updated.  | validation: format date-time


```

### Examples

### Create Campaign
Create a new email marketing campaign from MJML editor data.

```curl
curl -X POST \
'https://www.wixapis.com/email-marketing/v1/campaigns' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "composer": {
    "composerDataJson": "{\"mjml\":\"<mjml><mj-body><mj-section><mj-column><mj-text>Summer Sale! Get 20% off all products this week.</mj-text></mj-column></mj-section></mj-body></mjml>\"}"
  },
  "campaignEditorType": {
    "value": "MJML"
  },
  "emailSubject": "Summer Sale - 20% Off Everything",
  "emailPreheader": "Limited time offer inside"
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.emailMarketing.campaigns.create(composer, options)
 Description: Creates a new email marketing campaign from editor data.  The campaign is created as a draft. Call [Publish](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/publish.md) to send it to recipients.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  composer, composer.composerDataJson
 Method parameters: 
   param name: composer | type: Composer | description: Represents a campaign's editor data that is used to render the campaign in the editor and viewer. | required: true 
        - name: composerDataJson | type: string | description: Editor content for the campaign. The format depends on `campaignEditorType`:  - `WEB`: Wix proprietary JSON format used by the drag-and-drop email editor. - `MOBILE`: A subset of the `WEB` format, used by the mobile email editor. - `MJML`: MJML markup wrapped in a JSON object under key "mjml".  Passing the wrong format for the given `campaignEditorType` causes a silent failure when sending or previewing the campaign. | required: true | validation: maxLength 10000000
        - name: defaultValues | type: DefaultValues | description: Fallback values for dynamic placeholders in the campaign content.  
           - name: map | type: object | description: Map of placeholder keys to their default values.  | validation: maxItems 500, format map
   param name: options | type: CreateOptions  none  
        - name: campaignEditorType | type: CampaignEditorType | description: Editor type that determines the format of `composer.composerDataJson`.  Default: `WEB`  
           - name: value | type: Enum | description:   
                 - enum:
                 -     UNKNOWN: Unknown editor. This value isn't used.
                 -     WEB: Wix classic drag-and-drop email editor. The `composerDataJson` is stored in Wix proprietary JSON format.
                 -     MOBILE: Wix classic mobile-optimized email editor. The `composerDataJson` is stored in a subset of the `WEB` format.
                 -     MJML: AI-powered email editor. The `composerDataJson` is stored in MJML format wrapped in JSON.
        - name: emailSubject | type: string | description: Subject line displayed in recipients' inboxes (optional).  | validation: maxLength 1000
        - name: emailPreheader | type: string | description: Short preview text shown after the subject line in some email clients (optional).  | validation: maxLength 1000
 Return type: PROMISE<CreateCampaignResponse>
  - name: campaign | type: Campaign | description: Campaign information.  
     - name: campaignId | type: string | description: Campaign GUID.  | validation: format GUID
     - name: title | type: string | description: Campaign title. Used to identify the campaign in the dashboard. Defaults to the email subject if not provided.  
     - name: firstImageUrl | type: string | description: URL of the first image after the logo.  | validation: format WEB_URL
     - name: editorType | type: Enum | description: Editor type that determines the format of `composerDataJson`.  
         - enum:
         -     UNKNOWN: Unknown editor. This value isn't used.
         -     WEB: Wix classic drag-and-drop email editor. The `composerDataJson` is stored in Wix proprietary JSON format.
         -     MOBILE: Wix classic mobile-optimized email editor. The `composerDataJson` is stored in a subset of the `WEB` format.
         -     MJML: AI-powered email editor. The `composerDataJson` is stored in MJML format wrapped in JSON.
     - name: status | type: Enum | description: Campaign status.  
         - enum:
         -     UNKNOWN: Unknown campaign. This value isn't used.
         -     ACTIVE: Campaign is active.
         -     ARCHIVED: Campaign is archived.
         -     DELETED: Campaign is deleted.
     - name: visibilityStatus | type: Enum | description: Whether the campaign is a draft, published, or a template.  
         - enum:
         -     UNKNOWN: Unknown status. This value isn't used.
         -     DRAFT: Campaign isn't published yet.
         -     PUBLISHED: Campaign is published.
         -     TEMPLATE: Campaign is a template.
     - name: distributionStatus | type: Enum | description: Campaign distribution status.  
         - enum:
         -     UNKNOWN: Unknown distribution status.
         -     NOT_STARTED: Campaign isn't distributed to recipients yet.
         -     SCHEDULED: Campaign is scheduled for distribution.
         -     IN_DETECTION: Campaign is in screening for malicious content.
         -     IN_MODERATION: Campaign is in review by the site moderators.
         -     SAMPLING: A subset of recipients receives the campaign first to check for deliverability issues before sending to the full audience.
         -     SENDING: Campaign is being sent out to all recipients.
         -     REJECTED: Campaign was identified as abusive and rejected before sending.
         -     TERMINATED: Campaign is terminated after a failed sampling test.
         -     DISTRIBUTED: Campaign is fully distributed to all recipients.
         -     PAUSED: Scheduled campaign is paused.
     - name: publishingData | type: PublishingData | description: Publishing data. The field is returned empty if the campaign isn't published.  
        - name: landingPageUrl | type: string | description: Landing page URL.  | validation: format WEB_URL
        - name: statistics | type: CampaignStatistics | description: Campaign engagement statistics.  
           - name: landingPage | type: LandingPageStatistics | description: Landing page statistics.  
              - name: opened | type: integer | description: Number of times the landing page was loaded or viewed.  
              - name: clicked | type: integer | description: Number of times a link was clicked in a landing page.  
           - name: emailCampaign | type: DistributionStatistics | description: Email distribution statistics.  
              - name: delivered | type: integer | description: Number of delivered emails.  
              - name: opened | type: integer | description: Number of recipients who opened an email.  If the same recipient opened the same email twice, it is counted as a one unique open.  
              - name: clicked | type: integer | description: Number of recipients who clicked a link in the email.  If the same recipient clicked the same link twice, it is counted as a one unique click.  If the same recipient clicked different links, it is counted as a one unique click.  
              - name: bounced | type: integer | description: Number of emails that didn't reach the recipient.  
              - name: complained | type: integer | description: Number of recipients who reported the email as spam.  
              - name: notSent | type: integer | description: Number of emails that weren't sent due to campaign termination.  
           - name: total | type: TotalStatistics | description: Combined statistics of landing page and email distribution.  
              - name: mailsSent | type: integer | description: Total number of emails sent.  
              - name: opened | type: integer | description: Number of landing page views and opened emails.  
              - name: clicked | type: integer | description: Number of landing page and email link clicks.  
        - name: datePublished | type: Date | description: Date and time the campaign was published.  
        - name: wasResentToNonOpeners | type: boolean | description: Whether the campaign was resent to recipients who didn't open the original email.  
     - name: dateCreated | type: Date | description: Date and time the campaign was created.  
     - name: dateUpdated | type: Date | description: Date and time the campaign was updated.  


```

### Examples

### create
```javascript
import { campaigns } from '@wix/email-marketing';

async function create(composer,options) {
  const response = await campaigns.create(composer,options);
};
```

### create (with elevated permissions)
```javascript
import { campaigns } from '@wix/email-marketing';
import { auth } from '@wix/essentials';

async function myCreateMethod(composer,options) {
  const elevatedCreate = auth.elevate(campaigns.create);
  const response = await elevatedCreate(composer,options);
}
```

### create (self-hosted)
Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { campaigns } from '@wix/email-marketing';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { campaigns },
  // Include the auth strategy and host as relevant
});


async function create(composer,options) {
  const response = await myWixClient.campaigns.create(composer,options);
};
```

---