> 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 # Publish # Package: emailMarketing # Namespace: CampaignService # Method link: https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-marketing/campaign/publish-campaign.md ## Permission Scopes: Manage Email Marketing: SCOPE.DC-PROMOTE.EMAIL-MARKETING ## Introduction Publishes and sends a specified campaign. If the `email_distribution_options` object isn't passed in the request, the campaign is only published as a landing page. --- ## REST API ### Schema ``` Method: publish Description: Publishes and sends a specified campaign. If the `email_distribution_options` object isn't passed in the request, the campaign is only published as a landing page. URL: https://www.wixapis.com/email-marketing/v1/campaigns/{campaignId}/publish Method: POST Method parameters: param name: emailDistributionOptions | type: EmailDistributionOptions - name: emailSubject | type: string | description: The subject line for the email campaign, which appears in recipients’ inboxes. - name: labelIds | type: array | description: Contact label GUIDs. - name: contactIds | type: array | description: IDs of contacts to whom to send out the campaign. - name: sendAt | type: string | description: Campaign scheduling. You can schedule the campaign no less than 30 minutes until the sending time. [Upgrade your plan](https://support.wix.com/en/article/email-marketing-upgrading-your-email-marketing-plan) to schedule the campaign. Return type: PublishCampaignResponse - name: publishingData | type: PublishingData | description: Publishing info. - name: landingPageUrl | type: string | description: Landing page URL. - name: statistics | type: CampaignStatistics | description: Marketing campaign statistics. - name: landingPage | type: LandingPageStatistics | description: Landing page statistics of a marketing campaign. - name: opened | type: integer | description: Number of times when a 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 of a marketing campaign. - 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 a spam. - name: notSent | type: integer | description: Number of emails that weren't sent due to the 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: Marketing campaign publish date. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SEND_AT | Description: Invalid time for scheduled campaign. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SCHEDULING_FEATURE_UNAVAILABLE | Description: Scheduling feature not available. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: ALREADY_PUBLISHED | Description: Campaign has already been published. ``` ### Examples ### Publish Campaign ```curl curl -X POST 'https://www.wixapis.com/email-marketing/v1/campaigns/98b5a0b3-549b-4e58-b933-a8bd40923a14/publish' \ -H 'Content-Type: application/json' \ -H 'Authorization: ' -d '{ "emailDistributionOptions": { "emailSubject": "Yoga with puppies", "labelIds": ["contacts-all"] } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.emailMarketing.CampaignService.publish(campaignId, options) Description: Publishes and sends a specified campaign. If the `email_distribution_options` object isn't passed in the request, the campaign is only published as a landing page. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: campaignId Method parameters: param name: campaignId | type: string | description: Campaign GUID | required: true param name: options | type: PublishOptions none - name: emailDistributionOptions | type: EmailDistributionOptions | description: Email distribution options. Pass this object in the request if you need to distribute your marketing campaign with emails. - name: emailSubject | type: string | description: The subject line for the email campaign, which appears in recipients’ inboxes. - name: labelIds | type: array | description: Contact label GUIDs. - name: contactIds | type: array | description: IDs of contacts to whom to send out the campaign. - name: sendAt | type: Date | description: Campaign scheduling. You can schedule the campaign no less than 30 minutes until the sending time. [Upgrade your plan](https://support.wix.com/en/article/email-marketing-upgrading-your-email-marketing-plan) to schedule the campaign. Return type: PROMISE - name: publishingData | type: PublishingData | description: Publishing info. - name: landingPageUrl | type: string | description: Landing page URL. - name: statistics | type: CampaignStatistics | description: Marketing campaign statistics. - name: landingPage | type: LandingPageStatistics | description: Landing page statistics of a marketing campaign. - name: opened | type: integer | description: Number of times when a 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 of a marketing campaign. - 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 a spam. - name: notSent | type: integer | description: Number of emails that weren't sent due to the 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: Marketing campaign publish date. Possible Errors: HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SEND_AT | Description: Invalid time for scheduled campaign. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SCHEDULING_FEATURE_UNAVAILABLE | Description: Scheduling feature not available. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: ALREADY_PUBLISHED | Description: Campaign has already been published. ``` ### Examples ### Publishes specified campaign (with elevated permissions) ```javascript import { campaigns } from '@wix/email-marketing'; import { auth } from '@wix/essentials'; const elevatedPublishCampaign = auth.elevate(campaigns.publishCampaign); // Sample campaignId = "ea46013c-bbbf-4617-ad5d-9247bc4c0970"; export async function myPublishCampaignFunction(campaignId) { try { const result = await elevatedPublishCampaign(campaignId); console.log(`Success! Your campaign with id: ${campaignId} has been published.`) return result; } catch (error) { console.error(error); } } /* Promise resolves to: * { * "publishingData": { * "landingPageUrl": "https://shoutout.wix.com/so/88OduoI8E?languageTag=en", * "datePublished": "2023-08-17T11:11:06.000Z", * "wasResentToNonOpeners": false, * "statistics": { * "landingPage": { * "opened": 150, * "clicked": 80 * }, * "emailCampaign": { * "opened": 200, * "clicked": 0, * "bounced": 0, * "complained": 0, * "notSent": 0 * }, * "total": { * "mailsSent": 1, * "opened": 200, * "clicked": 500 * } * } * } * } */ ``` ### Publishes specified campaign ```javascript import { campaigns } from '@wix/email-marketing'; // Sample campaignId = "ea46013c-bbbf-4617-ad5d-9247bc4c0970"; export async function myPublishCampaignFunction(campaignId) { try { const result = await campaigns.publishCampaign(campaignId); console.log(`Success! Your campaign with id: ${campaignId} has been published.`) return result; } catch (error) { console.error(error); } } /* Promise resolves to: * { * "publishingData": { * "landingPageUrl": "https://shoutout.wix.com/so/88OduoI8E?languageTag=en", * "datePublished": "2023-08-17T11:11:06.000Z", * "wasResentToNonOpeners": false, * "statistics": { * "landingPage": { * "opened": 150, * "clicked": 80 * }, * "emailCampaign": { * "opened": 200, * "clicked": 0, * "bounced": 0, * "complained": 0, * "notSent": 0 * }, * "total": { * "mailsSent": 1, * "opened": 200, * "clicked": 500 * } * } * } * } */ ``` ### publishCampaign (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 publishCampaign(campaignId,options) { const response = await myWixClient.campaigns.publishCampaign(campaignId,options); }; ``` ---