This guide will walk you through steps to delete an existing campaign from your account.
Required Access Level: ModifyCampaigns
When using Elastic Email, when you send an email to any group of contacts we call that a "campaign".
It's NodeJS code, so make sure you have it installed or download it here: https://nodejs.org/en/download/
Create a new JavaScript file snippet.js
and open it in editor of your preference eg. Visual Studio Code (https://code.visualstudio.com/)
Put the below code to your file.
Load library using below line:
const ElasticEmail = require('@elasticemail/elasticemail-client');
Get client instance:
const client = ElasticEmail.ApiClient.instance;
Generate and use your API key (remember to check a required access level):
const apikey = client.authentications['apikey'];
apikey.apiKey = "YOUR_API_KEY";
Create an instance of CampaignsApi that will be used to delete a campaign.
const campaignsApi = new ElasticEmail.CampaignsApi()
The only thing you need to specify is a campaign name
Find out more by checking our API's documentation: https://elasticemail.com/developers/api-documentation/rest-api#operation/campaignsByNameDelete
const campaignName = "example";
Create a callback function that will be called when response comes back.
In case of error it will display error details, otherwise it will display a success messages.
const callback = (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully.');
console.log('Campaign deleted.');
}
};
And finally, call campaignsByNameDelete
method from the API to delete a campaign:
campaignsApi.campaignsByNameDelete(campaignName, callback);
const ElasticEmail = require('@elasticemail/elasticemail-client');
const client = ElasticEmail.ApiClient.instance;
const apikey = client.authentications['apikey'];
apikey.apiKey = "YOUR_API_KEY";
const campaignsApi = new ElasticEmail.CampaignsApi()
const campaignName = "hello campaign";
const callback = (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully.');
console.log('Campaign deleted.');
}
};
campaignsApi.campaignsByNameDelete(campaignName, callback);
node snippet.js