-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploadContacts.js
41 lines (34 loc) · 1.03 KB
/
uploadContacts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Initialization */
const ElasticEmail = require('@elasticemail/elasticemail-client');
const client = ElasticEmail.ApiClient.instance;
/* Generate and use your API key */
const apikey = client.authentications['apikey'];
apikey.apiKey = "YOUR_API_KEY";
/**
* Upload contacts
* Example api call that adds new contacts by uploading csv file.
* Required columns in CSV file: Email.
* Suggested columns in CSV file: AllowUnsubscribe, Status, ConsentDate, ConsentIP, ConsentTracking.
*
* Example CSV file content:
*
* Email
* john@johnsmith.com
*/
const fs = require('fs');
const contactsApi = new ElasticEmail.ContactsApi()
const readStream = fs.createReadStream('./files/contacts.csv');
const options = {
listName: "New list",
encodingName: 'utf-8',
file: readStream,
};
const callback = (error, data, response) => {
if (error) {
console.error(error);
} else {
console.log('API called successfully.');
console.log('Contacts added.');
}
};
contactsApi.contactsImportPost(options, callback);