### Install and Build Project Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/README.md Installs project dependencies and builds the TypeScript sources to JavaScript. This is a prerequisite for publishing or consuming the library. ```bash npm install npm run build ``` -------------------------------- ### Complete Code Example for Exporting Contacts Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/exportContacts.md A full code example combining initialization, configuration, and the export function call for exporting contacts. ```javascript /* Initialization */ import { Configuration, ContactsApi, ExportFileFormats, CompressionFormat } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const contactsApi = new ContactsApi(config); /* You can't provide both a rule and list of emails, only one or the other. */ const rule = 'exampleFilterRule'; // string or undefined if you want to provide list of emails const emails = ['example@example.com']; // string[] or empty Array if you want to provide a rule const fileFormat = 'Csv'; // interface ExportFileFormats: 'Csv' || 'Xml' || 'Json' const compressionFormat = 'None'; // interface CompressionFormat: 'None || 'Zip const fileName = 'fileName.csv'; // name of your file including extension in string const exportContacts = (fileFormat: ExportFileFormats, rule: string, emails: string[], compressionFormat: CompressionFormat, fileName: string): void => { contactsApi.contactsExportPost(fileFormat, rule, emails, compressionFormat, fileName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; exportContacts(fileFormat, rule, emails, compressionFormat, fileName) ``` -------------------------------- ### Complete Code Example for Loading List Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadList.md This snippet combines initialization, configuration, API instantiation, list name definition, the loadList function, and its execution into a single, runnable example. ```javascript /* Initialization */ import { Configuration, ListsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const listsApi = new ListsApi(config); const listName = 'Example list' // string const loadList = (listName: string): void => { listsApi.listsByNameGet(listName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; loadList(listName) ``` -------------------------------- ### Complete Elastic Email Statistics Loading Example Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadStatistics.md A complete TypeScript example demonstrating initialization, date range definition, and loading statistics using the Elastic Email API. ```javascript /* Initialization */ import { Configuration, StatisticsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const statisticsApi = new StatisticsApi(config); /* dates in YYYY-MM-DDThh:mm:ss format */ const fromDate = new Date('2015-01-01').toJSON(); // string const toDate = new Date('2022-01-01').toJSON(); // string or null const loadStatistics = (fromDate: string, toDate?: string): void => { statisticsApi.statisticsGet(fromDate, toDate).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; loadStatistics(fromDate, toDate) ``` -------------------------------- ### Complete Delete Contact Example Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteContact.md A complete TypeScript example demonstrating the initialization, configuration, and deletion of a contact. ```javascript /* Initialization */ import { Configuration, ContactsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const contactsApi = new ContactsApi(config); const contact = 'example@address.com'; // string const deleteContact = (contact: string): void => { contactsApi.contactsByEmailDelete(contact).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; deleteContact(contact); ``` -------------------------------- ### Complete Code Example for Adding Contacts Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addContacts.md A comprehensive TypeScript example demonstrating the initialization, configuration, and execution of adding contacts via the ElasticEmail API. ```javascript /* Initialization */ import { Configuration, ContactsApi, ContactPayload } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const contactsApi = new ContactsApi(config); const contacts = [{ Email: "example@address.com", FirstName: "John", LastName: "Smith" }, { Email: "test@address.com", FirstName: "Test", LastName: "Test" } ]; // interface ContactPayload[] from '@elasticemail/elasticemail-client-ts-axios' const listNames = ["My list"]; // string[] const addContacts = (contacts: ContactPayload[], listNames: string[]): void => { contactsApi.contactsPost(contacts, listNames).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; addContacts(contacts, listNames) ``` -------------------------------- ### Complete Delete Campaign Example Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteCampaign.md A complete, runnable code example demonstrating the initialization, configuration, and deletion of a campaign using the Elastic Email API. ```javascript /* Initialization */ import { Configuration, CampaignsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const campaignsApi = new CampaignsApi(config); const campaignName = "example"; // string const deleteCampaign = (campaignName: string): void => { campaignsApi.campaignsByNameDelete(campaignName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; deleteCampaign(campaignName) ``` -------------------------------- ### Complete Code Example for Uploading Contacts Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/uploadContacts.md A comprehensive TypeScript example demonstrating the initialization, configuration, and execution of the contact upload process, including handling the file and API call. ```javascript /* Initialization */ import { Configuration, ContactsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const contactsApi = new ContactsApi(config); const listName = 'My list'; // string const encodingName = 'utf-8'; // string /* CSV file with contacts list. For example you can use file uploaded by input type="file" */ const file = example_file; // string const uploadContacts = (listName: string, encodingName: string, file: any): void => { contactsApi.contactsImportPost(listName, encodingName, file).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); } uploadContacts(listName, encodingName, file); ``` -------------------------------- ### Complete Campaign Creation Code Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addCampaign.md This is the full code example combining initialization, configuration, campaign definition, and the function call to create a campaign. ```javascript /* Initialization */ import { Configuration, CampaignsApi, Campaign } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const campaignsApi = new CampaignsApi(config); const newCampaign = { Name: 'New campaign', Recipients: { ListNames: ["my list name"], SegmentNames: null, }, Content: [{ From: 'myemail@address.com', ReplyTo: 'myemail@address.com', TemplateName: "your_template", Subject: 'Hello' }], Status: "selected_status" }; // interface Campaign from '@elasticemail/elasticemail-client-ts-axios' const addCampaign = (newCampaign: Campaign): void => { campaignsApi.campaignsPost(newCampaign).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; addCampaign(newCampaign); ``` -------------------------------- ### Install Unpublished Package Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/README.md Installs the elasticemail-client-ts-axios package from a local path. This is not recommended for production use. ```bash npm install PATH_TO_GENERATED_PACKAGE --save ``` -------------------------------- ### Complete code example for adding a list Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addList.md This snippet combines all the necessary steps: initialization, configuration, list definition, and the function call to add a new list to ElasticEmail. ```javascript /* Initialization */ import { Configuration, ListsApi, ListPayload } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const listsApi = new ListsApi(config); const listPayload = { ListName: "New list", AllowUnsubscribe: true, Emails: ["example@address.com"] // existing emails or empty to add all contacts }; // interface ListPayload from '@elasticemail/elasticemail-client-ts-axios' const addList = (listPayload: ListPayload): void => { listsApi.listsPost(listPayload).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; addList(listPayload) ``` -------------------------------- ### Complete Code Example for Updating a Campaign Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/updateCampaign.md This snippet combines all the necessary parts for updating a campaign, including initialization, configuration, and the update function call. ```javascript /* Initialization */ import { Configuration, CampaignsApi, Campaign } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const campaignsApi = new CampaignsApi(config); const campaignName = 'Example'; // string const updatedCampaign = { Name: 'Updated example campaign', Recipients: { ListNames: ["my list name"], SegmentNames: null, }, Content: [{ From: 'myemail@address.com', ReplyTo: 'myemail@address.com', TemplateName: "your_template", Subject: 'Updated campaign' }], Status: "selected_status" }; // interface Campaign from '@elasticemail/elasticemail-client-ts-axios' const updateCampaign = (campaignName: string, updatedCampaign: Campaign): void => { campaignsApi.campaignsByNamePut(campaignName, updatedCampaign).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; updateCampaign(campaignName, updatedCampaign) ``` -------------------------------- ### Complete Code Example Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteList.md A complete, copy-pasteable code snippet that includes initialization, list name definition, the delete function, and its execution. ```javascript /* Initialization */ import { Configuration, ListsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const listsApi = new ListsApi(config); const listName = 'Example list' // string const deleteList = (listName: string): void => { listsApi.listsByNameDelete(listName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; deleteList(listName) ``` -------------------------------- ### Complete Code Example for Adding a Template Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addTemplate.md This is the full code snippet combining initialization, configuration, payload definition, and the function call to add a template. Ensure you replace 'YOUR_API_KEY' with your actual API key. ```javascript /* Initialization */ import { Configuration, TemplatesApi, TemplatePayload } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const templatesApi = new TemplatesApi(config); const templatePayload = { Name: 'New template', Subject: 'Default subject', Body: [{ ContentType: 'HTML', Charset: 'utf-8', Content: '
My template
' }], TemplateScope: 'Personal', }; // interface TemplatePayload from '@elasticemail/elasticemail-client-ts-axios' const addTemplate = (templatePayload: TemplatePayload): void => { templatesApi.templatesPost(templatePayload).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; addTemplate(templatePayload) ``` -------------------------------- ### Install Published Package Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/README.md Installs the published version of the elasticemail-client-ts-axios package as a dependency for your project. This is the recommended method for consumption. ```bash npm install elasticemail-client-ts-axios@4.0.28 --save ``` -------------------------------- ### Complete Code Example for Loading Campaign Statistics Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaignsStats.md A complete, copy-pasteable code snippet that includes initialization, configuration, and the function call to load campaign statistics. ```javascript /* Initialization */ import { Configuration, StatisticsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const statisticsApi = new StatisticsApi(config); const limit = 0; // number const offset = 0; // number const loadCampaignsStats = (limit: number, offset: number): void => { statisticsApi.statisticsCampaignsGet(limit, offset).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; loadCampaignsStats(limit, offset) ``` -------------------------------- ### Complete Code Example for Deleting a Template Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteTemplate.md A consolidated code snippet demonstrating the initialization, configuration, and deletion of a template using the ElasticEmail SDK. ```javascript /* Initialization */ import { Configuration, TemplatesApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const templatesApi = new TemplatesApi(config); const templateName = 'Example template'; // string const deleteTemplate = (templateName: string): void => { templatesApi.templatesByNameDelete(templateName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; deleteTemplate(templateName) ``` -------------------------------- ### Complete Code Example for Loading Templates Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadTemplate.md A comprehensive code snippet that includes all necessary imports, configuration, API instantiation, template name definition, the load template function, and its invocation. ```javascript /* Initialization */ import { Configuration, TemplatesApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const templatesApi = new TemplatesApi(config); const templateName = 'Example template'; // string const loadTemplate = (templateName: string): void => { templatesApi.templatesByNameGet(templateName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; loadTemplate(templateName) ``` -------------------------------- ### Complete ElasticEmail Channel Statistics Code Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadChannelsStats.md A complete TypeScript example demonstrating initialization, configuration, and fetching channel statistics using the ElasticEmail API. ```javascript /* Initialization */ import { Configuration, StatisticsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const statisticsApi = new StatisticsApi(config); const limit = 0; // number const offset = 0; // number const loadChannelsStats = (limit: number, offset: number): void => { statisticsApi.statisticsChannelsGet(limit, offset).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; loadChannelsStats(limit, offset) ``` -------------------------------- ### Complete ElasticEmail Bulk Email Sending Code Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendBulkEmails.md A complete, copy-pasteable TypeScript example demonstrating the initialization, configuration, message definition, and sending of bulk emails. ```javascript /* Initialization */ import { Configuration, EmailsApi, EmailMessageData } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const emailsApi = new EmailsApi(config); const emailMessageData = { Recipients: [ { Email: "example@address.com", Fields: { name: "Name" } } ], Content: { Body: [ { ContentType: "HTML", Charset: "utf-8", Content: "Hi {name}!" }, { ContentType: "PlainText", Charset: "utf-8", Content: "Hi {name}!" } ], From: "myemail@address.com", Subject: "Example bulk email" } }; // interface EmailMessageData from '@elasticemail/elasticemail-client-ts-axios' const sendBulkEmails = (emailMessageData: EmailMessageData): void => { emailsApi.emailsPost(emailMessageData).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; sendBulkEmails(emailMessageData) ``` -------------------------------- ### Complete Transactional Email Sending Code Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendTransactionalEmails.md A full example combining initialization, configuration, email data definition, and the function call to send a transactional email. ```javascript /* Initialization */ import { Configuration, EmailsApi, EmailTransactionalMessageData } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const emailsApi = new EmailsApi(config); const emailTransactionalMessageData = { Recipients: { To: ["example@address.com"] // maximum 50 recipients }, Content: { Body: [ { ContentType: "HTML", Charset: "utf-8", Content: "Example content" }, { ContentType: "PlainText", Charset: "utf-8", Content: "Example content" } ], From: "myemail@address.com", Subject: "Example transactional email" } }; // interface EmailTransactionalMessageData from '@elasticemail/elasticemail-client-ts-axios' const sendTransactionalEmails = (emailTransactionalMessageData: EmailTransactionalMessageData): void => { emailsApi.emailsTransactionalPost(emailTransactionalMessageData).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; sendTransactionalEmails(emailTransactionalMessageData); ``` -------------------------------- ### Call Export Contacts Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/exportContacts.md Execute the `exportContacts` function with the defined parameters to start the export process. ```javascript exportContacts(fileFormat, rule, emails, compressionFormat, fileName) ``` -------------------------------- ### Define Date Range for Statistics Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadStatistics.md Specify the start date and an optional end date for the statistics report. Dates should be in ISO 8601 format. ```javascript const fromDate = new Date('2015-01-01').toJSON(); // string const toDate = new Date('2022-01-01').toJSON(); // string or null ``` -------------------------------- ### Event Listener for File Selection Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/uploadContacts.md Sets up an event listener on the file input to capture the selected file when the user makes a selection. ```javascript input.addEventListener('change', saveFile); let file; const saveFile = (event) => { file = event.target.files[0]; } ``` -------------------------------- ### Initialize Contacts API Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteContact.md Create an instance of the ContactsApi using the configuration object. ```javascript const contactsApi = new ContactsApi(config); ``` -------------------------------- ### Initialize EmailsApi Instance Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendBulkEmails.md Create an instance of EmailsApi to interact with the email sending functionality. ```javascript const emailsApi = new EmailsApi(config); ``` -------------------------------- ### Import Elastic Email Client Libraries Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadList.md Import the necessary Configuration class and ListsApi from the Elastic Email client library. ```javascript import { Coonfiguration, ListsApi } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Instantiate Campaigns API Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaign.md Create an instance of the CampaignsApi using the configuration object. This instance will be used to interact with the campaign-related API endpoints. ```javascript const campaignsApi = new CampaignsApi(config); ``` -------------------------------- ### Instantiate Lists API Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadList.md Create an instance of the ListsApi using the provided configuration to interact with list-related endpoints. ```javascript const listsApi = new ListsApi(config); ``` -------------------------------- ### Define Report Pagination Options Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadChannelsStats.md Set pagination parameters like limit and offset for fetching channel statistics. A limit of 0 retrieves all available items. ```javascript const limit = 0; // number const offset = 0; // number ``` -------------------------------- ### Initialize Templates API Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteTemplate.md Instantiate the TemplatesApi class using the configuration object to interact with template-related API endpoints. ```javascript const templatesApi = new TemplatesApi(config); ``` -------------------------------- ### Initialize Statistics API Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadChannelsStats.md Instantiate the StatisticsApi class using the provided configuration to interact with statistics endpoints. ```javascript const statisticsApi = new StatisticsApi(config); ``` -------------------------------- ### Import ElasticEmail SDK Classes Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteTemplate.md Import the Configuration and TemplatesApi classes from the ElasticEmail SDK for TypeScript. ```javascript import { Configuration, TemplatesApi } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Configure API Key Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteTemplate.md Create a Configuration object with your API key for authenticating with the ElasticEmail API. ```javascript const config = new Configuration({ apiKey: "YOUR_API_KEY" }); ``` -------------------------------- ### Set Export Options Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/exportContacts.md Configure the export options, including the desired file format (CSV, XML, JSON), compression format (None, Zip), and the name for the output file. ```javascript const fileFormat = 'Csv'; // interface ExportFileFormats: 'Csv' || 'Xml' || 'Json' const compressionFormat = 'None'; // interface CompressionFormat: 'None || 'Zip const fileName = 'fileName.csv'; // name of your file including extension in string ``` -------------------------------- ### Load Campaign Details Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaign.md Implement a function to fetch campaign details by name using the `campaignsByNameGet` method. It logs the response data on success or errors on failure. ```javascript const loadCampaign = (campaignName: string): void => { campaignsApi.campaignsByNameGet(campaignName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Import necessary classes and interfaces Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addList.md Import the Configuration, ListsApi, and ListPayload from the elasticemail-ts-axios library. These are essential for setting up the client and defining list data. ```javascript import { Coonfiguration, ListsApi, ListPayload } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Implement Send Bulk Emails Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendBulkEmails.md Create a function to send bulk emails using the emailsApi.emailsPost method. It handles success and error logging. ```javascript const sendBulkEmails = (emailMessageData: EmailMessageData): void => { emailsApi.emailsPost(emailMessageData).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Import ElasticEmail Client Classes Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadChannelsStats.md Import necessary classes and interfaces from the ElasticEmail client library for TypeScript. ```javascript import { Configuration, StatisticsApi } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Execute Load Campaign Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaign.md Call the `loadCampaign` function with the specified campaign name to initiate the process of loading campaign details. ```javascript loadCampaign(campaignName); ``` -------------------------------- ### Complete Elastic Email Campaign Loading Code Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaign.md This snippet includes all necessary parts for loading campaign details: initialization, API key configuration, API instantiation, campaign name specification, the loading function, and its execution. ```javascript /* Initialization */ import { Configuration, CampaignsApi } from '@elasticemail/elasticemail-client-ts-axios'; /* Generate and use your API key */ const config = new Configuration({ apiKey: "YOUR_API_KEY" }); const campaignsApi = new CampaignsApi(config); const campaignName = "example"; // string const loadCampaign = (campaignName: string): void => { campaignsApi.campaignsByNameGet(campaignName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; loadCampaign(campaignName); ``` -------------------------------- ### Import ElasticEmail Client Classes Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addContacts.md Import the necessary classes and interfaces from the elasticemail-ts-axios library for contact management. ```javascript import { Configuration, ContactsApi, ContactPayload } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Import Necessary Classes Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteContact.md Import the Configuration and ContactsApi classes from the elasticemail-ts-axios library. ```javascript import { Configuration, ContactsApi } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Call the addList function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addList.md Execute the addList function with the prepared listPayload to create the new list in ElasticEmail. ```javascript addList(listPayload); ``` -------------------------------- ### Import Elastic Email Client Libraries Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addCampaign.md Import necessary classes and interfaces from the Elastic Email client library for TypeScript and Axios. ```javascript import { Configuration, CampaignsApi, Campaign } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Import Elastic Email Client Libraries Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaign.md Import necessary classes and interfaces from the Elastic Email client library for TypeScript and Axios. ```javascript import { Configuration, CampaignsApi } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Load Template Details Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadTemplate.md Implement a function that calls the `templatesByNameGet` method to fetch template details. It handles both successful responses and errors, logging the data or error details respectively. ```javascript const loadTemplate = (templateName: string): void => { templatesApi.templatesByNameGet(templateName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Import Elastic Email Client Libraries Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addTemplate.md Import the necessary classes and interfaces from the Elastic Email client library for TypeScript and Axios. ```javascript import { Configuration, TemplatesApi, TemplatePayload } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Import ElasticEmail SDK Classes Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendBulkEmails.md Import necessary classes and interfaces from the ElasticEmail SDK for TypeScript/Axios. ```javascript import { Configuration, EmailsApi, EmailMessageData } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### HTML Input and Button for File Upload Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/uploadContacts.md Provides the HTML elements for a file input and a button to trigger the contact upload process. ```html ``` -------------------------------- ### Execute Add Contacts Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addContacts.md Call the addContacts function with the prepared contact data and list names to initiate the contact addition process. ```javascript addContacts(contacts, listNames); ``` -------------------------------- ### Load List Details Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadList.md Implement a function to call the listsByNameGet method, handling both successful responses and errors. It logs the list data or error details to the console. ```javascript const loadList = (listName: string): void => { listsApi.listsByNameGet(listName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Import ElasticEmail TS Axios Classes Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/exportContacts.md Import the necessary classes and interfaces from the ElasticEmail TS Axios client library for contact operations. ```javascript import { Configuration, ContactsApi, ExportFileFormats, CompressionFormat } from '@elasticemail/elasticemail-client-ts-axios'; ``` -------------------------------- ### Call Load Template Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadTemplate.md Execute the `loadTemplate` function with the specified template name to initiate the API call and retrieve the template details. ```javascript loadTemplate(templateName); ``` -------------------------------- ### Call Load Channels Statistics Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadChannelsStats.md Execute the loadChannelsStats function with the defined limit and offset to retrieve channel statistics. ```javascript loadChannelsStats(limit, offset); ``` -------------------------------- ### Execute Load List Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadList.md Call the loadList function with the defined list name to initiate the API request. ```javascript loadList(listName); ``` -------------------------------- ### Define List and Encoding Names Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/uploadContacts.md Declare variables for the contact list name and the file's encoding. Ensure the encoding is set correctly, typically 'utf-8'. ```javascript const listName = 'My list'; // string const encodingName = 'utf-8'; // string ``` -------------------------------- ### Load Channels Statistics Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadChannelsStats.md Define a function to call the statisticsChannelsGet method, handling success and error responses. This function fetches statistics for all channels. ```javascript const loadChannelsStats = (limit: number, offset: number): void => { statisticsApi.statisticsChannelsGet(limit, offset).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Call Load Campaign Statistics Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaignsStats.md Execute the loadCampaignsStats function with the defined limit and offset to fetch campaign statistics. ```javascript loadCampaignsStats(limit, offset); ``` -------------------------------- ### Add a new list using ListsApi Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addList.md Implement a function to call the listsPost method with the defined ListPayload. This function handles the API call and logs the response or any errors. ```javascript const addList = (listPayload: ListPayload): void => { listsApi.listsPost(listPayload).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); } ``` -------------------------------- ### Call Add Template Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addTemplate.md Execute the `addTemplate` function with the defined template payload to create the new template in your account. ```javascript addTemplate(templatePayload); ``` -------------------------------- ### Call Send Bulk Emails Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendBulkEmails.md Execute the sendBulkEmails function with the prepared email message data. ```javascript sendBulkEmails(emailMessageData); ``` -------------------------------- ### Specify Campaign Name Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaign.md Define the name of the campaign for which details are to be loaded. Ensure this matches an existing campaign name. ```javascript const campaignName = "example"; // string ``` -------------------------------- ### Specify Template Name Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteTemplate.md Define the name of the template you intend to delete. Ensure this matches the template's name in your account. ```javascript const templateName = 'My template' // string ``` -------------------------------- ### Load Campaign Statistics Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadCampaignsStats.md Define a function to call the statisticsCampaignsGet method. It handles successful responses by logging data and errors by logging the error details. ```javascript const loadCampaignsStats = (limit: number, offset: number): void => { statisticsApi.statisticsCampaignsGet(limit, offset).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Call Add Campaign Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addCampaign.md Execute the addCampaign function with the defined campaign object to create the campaign. ```javascript addCampaign(newCampaign); ``` -------------------------------- ### Call the Send Transactional Emails Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendTransactionalEmails.md Execute the sendTransactionalEmails function with the prepared email data to send the email. ```javascript sendTransactionalEmails(emailTransactionalMessageData); ``` -------------------------------- ### Function to Add Contacts Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addContacts.md Implement a function that calls the contactsPost method to add contacts to your account. It handles success and error responses by logging messages to the console. ```javascript const addContacts = (contacts: ContactPayload[], listNames: string[]): void => { contactsApi.contactsPost(contacts, listNames).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); } ``` -------------------------------- ### Execute Campaign Update Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/updateCampaign.md Call the `updateCampaign` function with the campaign name and the updated campaign object to perform the update. ```javascript updateCampaign(campaignName, updatedCampaign) ``` -------------------------------- ### Define List Payload Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addList.md Create a ListPayload object containing the details for the new list, including the required ListName, AllowUnsubscribe setting, and an optional array of initial email addresses. ```javascript const listPayload = { ListName: "New list", AllowUnsubscribe: true, Emails: ["example@address.com"] // existing emails or empty to add all contacts }; // interface ListPayload from '@elasticemail/elasticemail-client-ts-axios' ``` -------------------------------- ### Load Statistics Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadStatistics.md Define a function to call the statisticsGet method, handling both successful responses and errors. It logs the retrieved data or error details. ```javascript const loadStatistics = (fromDate: string, toDate?: string): void => { statisticsApi.statisticsGet(fromDate, toDate).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Define Campaign Object Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addCampaign.md Construct a campaign object with essential details like name, recipients, content, and status. The status 'Draft' postpones sending. ```javascript const newCampaign = { Name: 'New campaign', Recipients: { ListNames: ['my list name'], SegmentNames: null, }, Content: [{ From: 'myemail@address.com', ReplyTo: 'myemail@address.com', TemplateName: 'your_template', Subject: 'Hello' }], Status: 'Draft' }; // interface Campaign from '@elasticemail/elasticemail-client-ts-axios' }; ``` -------------------------------- ### Define List Name Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadList.md Specify the name of the list for which you want to retrieve details. ```javascript const listName = 'Example list' // string ``` -------------------------------- ### Create Export Contacts Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/exportContacts.md Define a function that calls the `contactsExportPost` method to initiate the contact export. It handles success and error logging. ```typescript const exportContacts = (fileFormat: ExportFileFormats, rule: string, emails: string[], compressionFormat: CompressionFormat, fileName: string): void => { contactsApi.contactsExportPost(fileFormat, rule, emails, compressionFormat, fileName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Call Upload Contacts Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/uploadContacts.md Initiates the contact upload process by calling the uploadContacts function with the defined list name, encoding, and the selected file. ```javascript uploadContacts(listName, encodingName, file); ``` -------------------------------- ### Create Function to Send Transactional Emails Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendTransactionalEmails.md Define a function that uses the emailsApi to send the transactional email. It includes success and error handling with console logs. ```javascript const sendTransactionalEmails = (emailTransactionalMessageData: EmailTransactionalMessageData): void => { emailsApi.emailsTransactionalPost(emailTransactionalMessageData).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Call Load Statistics Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/loadStatistics.md Execute the loadStatistics function with the defined date range to fetch and display the statistics. ```javascript loadStatistics(fromDate, toDate); ``` -------------------------------- ### Add Campaign Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addCampaign.md Implement a function to call the campaignsPost API method. It handles success by logging the response data and errors by logging the error details. ```javascript const addCampaign = (newCampaign: Campaign): void => { campaignsApi.campaignsPost(newCampaign).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); } ``` -------------------------------- ### Update Campaign Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/updateCampaign.md Implement a function that calls the `campaignsByNamePut` method to update campaign details. It handles success and error logging. ```javascript const updateCampaign = (campaignName: string, updatedCampaign: Campaign): void => { campaignsApi.campaignsByNamePut(campaignName, updatedCampaign).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Define Contact Payload Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addContacts.md Prepare an array of contact objects, each conforming to the ContactPayload interface. The 'Email' field is mandatory for each contact. ```javascript const contacts = [{ Email: "example@address.com", FirstName: "John", LastName: "Smith" }, { Email: "test@address.com", FirstName: "Test", LastName: "Test" } ]; // interface ContactPayload[] from '@elasticemail/elasticemail-client-ts-axios' ``` -------------------------------- ### Call Delete List Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteList.md Execute the deleteList function with the specified list name to initiate the deletion process. ```javascript deleteList(listName); ``` -------------------------------- ### Add New Template Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addTemplate.md Implement a function to add a new template using the `templatesPost` method. It handles successful responses by logging data and errors by logging the error details. ```javascript const addTemplate = (templatePayload: TemplatePayload): void => { templatesApi.templatesPost(templatePayload).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Define Export Rule or Email List Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/exportContacts.md Specify either a rule for filtering contacts (e.g., segment or status) or provide a list of specific email addresses for export. You cannot provide both. ```javascript const rule = 'exampleFilterRule'; // string or undefined if you want to provide list of emails const emails = []; // string[] or empty array if you want to provide a rule ``` -------------------------------- ### Define Updated Campaign Object Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/updateCampaign.md Construct a Campaign object containing the new details for the campaign. This includes Name, Recipients, Content, and Status. ```javascript const updatedCampaign = { Name: 'Updated example campaign', Recipients: { ListNames: ["my list name"], SegmentNames: null, }, Content: [{ From: 'myemail@address.com', ReplyTo: 'myemail@address.com', TemplateName: "your_template", Subject: 'Updated campaign' }], Status: "selected_status" }; // interface Campaign from '@elasticemail/elasticemail-client-ts-axios' ``` -------------------------------- ### Specify List Names for Contacts Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addContacts.md Define an array of strings representing the names of the lists to which the contacts should be added. If empty, contacts are added to all contacts. ```javascript const listNames = ["My list"]; // string[] ``` -------------------------------- ### Define Template Payload Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/addTemplate.md Construct the template payload object, specifying the name, subject, body content, and scope for the new template. The scope can be 'Personal' or 'Global'. ```javascript const templatePayload = { Name: 'New template', Subject: 'Default subject', Body: [{ ContentType: 'HTML', Charset: 'utf-8', Content: '
My template
' }], TemplateScope: 'Personal', }; // interface TemplatePayload from '@elasticemail/elasticemail-client-ts-axios' ``` -------------------------------- ### Contacts Upload Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/uploadContacts.md Defines the function to upload contacts using contactsApi.contactsImportPost. It handles success by logging the response data and errors by logging the error object. ```javascript const uploadContacts = (listName: string, encodingName: string, file: any): void => { contactsApi.contactsImportPost(listName, encodingName, file).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); } ``` -------------------------------- ### Define Bulk Email Message Data Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendBulkEmails.md Structure the email message data, including recipients with merge fields and multi-part content (HTML and PlainText). Ensure the 'From' address is validated. ```javascript const emailMessageData = { Recipients: [ { Email: "example@address.com", Fields: { name: "Name" } } ], Content: { Body: [ { ContentType: "HTML", Charset: "utf-8", Content: "Hi {name}!" }, { ContentType: "PlainText", Charset: "utf-8", Content: "Hi {name}!" } ], From: "myemail@address.com", Subject: "Example bulk email" } }; // interface EmailMessageData from '@elasticemail/elasticemail-client-ts-axios' ``` -------------------------------- ### Specify Contact Email Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteContact.md Define the email address of the contact to be deleted. ```javascript const contact = 'example@address.com'; // string ``` -------------------------------- ### Define Transactional Email Details Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/sendTransactionalEmails.md Structure the email message data, including recipients, sender, subject, and content in both HTML and plain text formats. The 'To' field supports up to 50 recipients. ```javascript const emailTransactionalMessageData = { Recipients: { To: ["example@address.com"] // maximum 50 recipients }, Content: { Body: [ { ContentType: "HTML", Charset: "utf-8", Content: "Example content" }, { ContentType: "PlainText", Charset: "utf-8", Content: "Example content" } ], From: "myemail@address.com", Subject: "Example transactional email" } }; // interface EmailTransactionalMessageData from '@elasticemail/elasticemail-client-ts-axios' ``` -------------------------------- ### Call Delete Template Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteTemplate.md Execute the `deleteTemplate` function with the specified template name to initiate the deletion process. ```javascript deleteTemplate(templateName); ``` -------------------------------- ### Call Delete Campaign Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteCampaign.md Execute the deleteCampaign function with the specified campaign name to initiate the deletion process. ```javascript deleteCampaign(campaignName); ``` -------------------------------- ### Delete List Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteList.md Defines a function to delete a list by its name using the listsByNameDelete method. It handles success and error responses. ```javascript const deleteList = (listName: string): void => { listsApi.listsByNameDelete(listName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Call Delete Contact Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteContact.md Execute the deleteContact function with the specified contact email. ```javascript deleteContact(contact); ``` -------------------------------- ### Delete Campaign Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteCampaign.md Define a function that calls the campaignsByNameDelete method to remove a campaign. It includes success and error handling with console logging. ```javascript const deleteCampaign = (campaignName: string): void => { campaignsApi.campaignsByNameDelete(campaignName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Delete Template Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteTemplate.md Implement a function to delete a template by its name using the `templatesByNameDelete` method. It handles success and error responses. ```javascript const deleteTemplate = (templateName: string): void => { templatesApi.templatesByNameDelete(templateName).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); }; ``` -------------------------------- ### Delete Contact Function Source: https://github.com/elasticemail/elasticemail-ts-axios/blob/master/examples/functions/deleteContact.md A function to delete a contact by email using the contactsByEmailDelete method. It logs success or error messages to the console. ```javascript const deleteContact = (contact: string): void => { contactsApi.contactsByEmailDelete(contact).then((response) => { console.log('API called successfully.'); console.log(response.data); }).catch((error) => { console.error(error); }); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.