Search.../

listCampaigns( )

Developer Preview

Returns a list of email campaigns.

Description

Default sort by date_updated in desc order.

This function is not a universal function and runs only on the backend.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function listCampaigns(options: ListCampaignsOptions): Promise<ListCampaignsResponse>

listCampaigns Parameters

NAME
TYPE
DESCRIPTION
options
Optional
ListCampaignsOptions

Options to use when getting the list of campaigns.

Returns

Return Type:

Promise<
ListCampaignsResponse
>
NAME
TYPE
DESCRIPTION
campaigns
Array<
Campaign
>

List of campaigns.

paging
Paging

Paging parameters.

Was this helpful?

Returns a list of email campaigns (dashboard page code)

Copy Code
1import { campaigns } from 'wix-email-marketing.v2';
2
3// Sample options value:
4// {
5// paging: {
6// limit: 2,
7// offset: 0
8// }
9// }
10
11export async function myListCampaignsFunction(options) {
12 try {
13 const results = await campaigns.listCampaigns(options);
14
15 console.log('Success! Retrieved results:', results);
16 return results;
17 } catch (error) {
18 console.error(error);
19 }
20}
21
22/* Promise resolves to:
23 * {
24 * "campaigns": [
25 * {
26 * "campaignId": "b98a4436-10f5-47bd-9c6f-370962adfe54",
27 * "title": "A New Tutorial for You",
28 * "firstImageUrl": "https://static.wixstatic.com/media/6191b8_77d27f7d028a4b50850b7f92dadcd578~mv2.png",
29 * "snapshotImageUrl": "https://images-wixmp-678e81504367d310e9a2f32f.wixmp.com/images/b98a4436-10f5-47bd-9c6f-370962adfe54-14dc2505-9fa6-461f-ad70-22358e1428c4",
30 * "editorType": "WEB",
31 * "status": "ACTIVE",
32 * "visibilityStatus": "PUBLISHED",
33 * "distributionStatus": "DISTRIBUTED",
34 * "publishingData": {
35 * "landingPageUrl": "https://shoutout.wix.com/so/54OdUqUrf?languageTag=en",
36 * "datePublished": "2023-08-10T09:40:59.000Z",
37 * "wasResentToNonOpeners": false
38 * },
39 * "dateCreated": "2023-08-10T09:40:47.000Z",
40 * "dateUpdated": "2023-08-10T09:40:59.045Z",
41 * "sendingState": "SENT",
42 * "campaignType": "EMAIL_MARKETING"
43 * },
44 * {
45 * "campaignId": "fb21c999-40b5-4364-8e75-18273da41983",
46 * "title": "What did we do last month?",
47 * "firstImageUrl": "https://static.wixstatic.com/media/eceb8e_e65cd7284b4c4144a4fb8b2f3ce30a68~mv2_d_2000_1334_s_2.png",
48 * "snapshotImageUrl": "https://images-wixmp-678e81504367d310e9a2f32f.wixmp.com/images/fb21c999-40b5-4364-8e75-18273da41983-160c479e-cbf5-4de4-8317-2162abd9c650",
49 * "editorType": "WEB",
50 * "status": "ACTIVE",
51 * "visibilityStatus": "PUBLISHED",
52 * "distributionStatus": "DISTRIBUTED",
53 * "publishingData": {
54 * "landingPageUrl": "https://shoutout.wix.com/so/83OdQ8pDA?languageTag=en",
55 * "datePublished": "2023-08-10T09:25:15.000Z",
56 * "wasResentToNonOpeners": false
57 * },
58 * "dateCreated": "2023-08-09T11:51:27.000Z",
59 * "dateUpdated": "2023-08-10T09:25:14.952Z",
60 * "sendingState": "SENT",
61 * "campaignType": "EMAIL_MARKETING"
62 * }
63 * ]
64 * }
65 */
Returns a list of email campaigns (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { campaigns } from 'wix-email-marketing.v2';
3
4// Sample options value:
5// {
6// paging: {
7// limit: 2,
8// offset: 0
9// }
10// }
11
12export const myListCampaignsFunction = webMethod(Permissions.Anyone, async (options) => {
13 try {
14 const results = await campaigns.listCampaigns(options);
15
16 console.log('Success! Retrieved results:', results);
17 return results;
18 } catch (error) {
19 console.error(error);
20 }
21});
22
23/* Promise resolves to:
24 * {
25 * "campaigns": [
26 * {
27 * "campaignId": "b98a4436-10f5-47bd-9c6f-370962adfe54",
28 * "title": "A New Tutorial for You",
29 * "firstImageUrl": "https://static.wixstatic.com/media/6191b8_77d27f7d028a4b50850b7f92dadcd578~mv2.png",
30 * "snapshotImageUrl": "https://images-wixmp-678e81504367d310e9a2f32f.wixmp.com/images/b98a4436-10f5-47bd-9c6f-370962adfe54-14dc2505-9fa6-461f-ad70-22358e1428c4",
31 * "editorType": "WEB",
32 * "status": "ACTIVE",
33 * "visibilityStatus": "PUBLISHED",
34 * "distributionStatus": "DISTRIBUTED",
35 * "publishingData": {
36 * "landingPageUrl": "https://shoutout.wix.com/so/54OdUqUrf?languageTag=en",
37 * "datePublished": "2023-08-10T09:40:59.000Z",
38 * "wasResentToNonOpeners": false
39 * },
40 * "dateCreated": "2023-08-10T09:40:47.000Z",
41 * "dateUpdated": "2023-08-10T09:40:59.045Z",
42 * "sendingState": "SENT",
43 * "campaignType": "EMAIL_MARKETING"
44 * },
45 * {
46 * "campaignId": "fb21c999-40b5-4364-8e75-18273da41983",
47 * "title": "What did we do last month?",
48 * "firstImageUrl": "https://static.wixstatic.com/media/eceb8e_e65cd7284b4c4144a4fb8b2f3ce30a68~mv2_d_2000_1334_s_2.png",
49 * "snapshotImageUrl": "https://images-wixmp-678e81504367d310e9a2f32f.wixmp.com/images/fb21c999-40b5-4364-8e75-18273da41983-160c479e-cbf5-4de4-8317-2162abd9c650",
50 * "editorType": "WEB",
51 * "status": "ACTIVE",
52 * "visibilityStatus": "PUBLISHED",
53 * "distributionStatus": "DISTRIBUTED",
54 * "publishingData": {
55 * "landingPageUrl": "https://shoutout.wix.com/so/83OdQ8pDA?languageTag=en",
56 * "datePublished": "2023-08-10T09:25:15.000Z",
57 * "wasResentToNonOpeners": false
58 * },
59 * "dateCreated": "2023-08-09T11:51:27.000Z",
60 * "dateUpdated": "2023-08-10T09:25:14.952Z",
61 * "sendingState": "SENT",
62 * "campaignType": "EMAIL_MARKETING"
63 * }
64 * ]
65 * }
66 */
67
Returns a list of email campaigns based on optional data

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { campaigns } from 'wix-email-marketing.v2';
3
4// Sample options value:
5// {
6// options: {
7// campaignType: 'AUTOMATION',
8// statuses: ['DELETED'],
9// visibilityStatuses: ['PUBLISHED]
10// }
11// }
12
13export const myListCampaignsFunction = webMethod(Permissions.Anyone, async (options) => {
14 try {
15 const results = await campaigns.listCampaigns(options);
16
17 console.log('Success! Retrieved results:', results);
18 return results;
19 } catch (error) {
20 console.error(error);
21 }
22});
23
24/* Promise resolves to:
25 * {
26 * "campaigns": [
27 * {
28 * "campaignId": "b98a4436-10f5-47bd-9c6f-370962adfe54",
29 * "title": "A New Tutorial for You",
30 * "firstImageUrl": "https://static.wixstatic.com/media/6191b8_77d27f7d028a4b50850b7f92dadcd578~mv2.png",
31 * "snapshotImageUrl": "https://images-wixmp-678e81504367d310e9a2f32f.wixmp.com/images/b98a4436-10f5-47bd-9c6f-370962adfe54-14dc2505-9fa6-461f-ad70-22358e1428c4",
32 * "editorType": "WEB",
33 * "status": "DELETED",
34 * "visibilityStatus": "PUBLISHED",
35 * "distributionStatus": "DISTRIBUTED",
36 * "publishingData": {
37 * "landingPageUrl": "https://shoutout.wix.com/so/54OdUqUrf?languageTag=en",
38 * "datePublished": "2023-08-10T09:40:59.000Z",
39 * "wasResentToNonOpeners": false
40 * },
41 * "dateCreated": "2023-08-10T09:40:47.000Z",
42 * "dateUpdated": "2023-08-10T09:40:59.045Z",
43 * "sendingState": "SENT",
44 * "campaignType": "EMAIL_MARKETING"
45 * },
46 * {
47 * "campaignId": "fb21c999-40b5-4364-8e75-18273da41983",
48 * "title": "What did we do last month?",
49 * "firstImageUrl": "https://static.wixstatic.com/media/eceb8e_e65cd7284b4c4144a4fb8b2f3ce30a68~mv2_d_2000_1334_s_2.png",
50 * "snapshotImageUrl": "https://images-wixmp-678e81504367d310e9a2f32f.wixmp.com/images/fb21c999-40b5-4364-8e75-18273da41983-160c479e-cbf5-4de4-8317-2162abd9c650",
51 * "editorType": "WEB",
52 * "status": "DELETED",
53 * "visibilityStatus": "PUBLISHED",
54 * "distributionStatus": "DISTRIBUTED",
55 * "publishingData": {
56 * "landingPageUrl": "https://shoutout.wix.com/so/83OdQ8pDA?languageTag=en",
57 * "datePublished": "2023-08-10T09:25:15.000Z",
58 * "wasResentToNonOpeners": false
59 * },
60 * "dateCreated": "2023-08-09T11:51:27.000Z",
61 * "dateUpdated": "2023-08-10T09:25:14.952Z",
62 * "sendingState": "SENT",
63 * "campaignType": "EMAIL_MARKETING"
64 * }
65 * ]
66 * }
67 */
Returns a list of email campaigns and adds the campaign title to your database

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { campaigns } from 'wix-email-marketing.v2';
3import wixData from 'wix-data';
4
5export const myListCampaignsFunction = webMethod(Permissions.Anyone, async () => {
6 try {
7 const result = await campaigns.listCampaigns();
8
9 const campaignTitle = result.campaigns.title[0].title;
10 console.log(campaignTitle);
11 // store campaign title in your database
12 let toInsert = {
13 "title": campaignTitle
14 };
15
16 const results = await wixData.insert('myDatabaseCollection', toInsert);
17 console.log(`Data inserted successfully. The item ID is: ${results._id}`); // Data inserted successfully. The item ID is: 532549d4-2a95-45cc-bb8e-4cb39422e42c
18 return { "title": campaignTitle }
19
20 } catch (error) {
21 console.error(error);
22 return { "Error": "Failed to find and insert data." };
23 }
24});
25
26/*
27 * Promise returns:
28 * {
29 * "title": "A New Tutorial for You"
30 * }
31 */
32