-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patheverything.ts
More file actions
47 lines (40 loc) · 1.14 KB
/
everything.ts
File metadata and controls
47 lines (40 loc) · 1.14 KB
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
42
43
44
45
46
47
import { MailtrapClient } from "mailtrap";
const TOKEN = "<YOUR-TOKEN-HERE>";
const ACCOUNT_ID = "<YOUR-ACCOUNT-ID-HERE>"
const client = new MailtrapClient({
token: TOKEN,
accountId: ACCOUNT_ID
});
const contactData = {
email: "john.smith@example.com",
fields: {
first_name: "John",
last_name: "Smith"
},
};
// Create contact first
client.contacts
.create(contactData)
.then(async (createResponse) => {
console.log("Contact created:", createResponse.data);
const contactId = createResponse.data.id;
// Get contact by email
const getResponse = await client.contacts.get(contactData.email);
console.log("Contact retrieved:", getResponse.data);
// Update contact
const updateResponse = await client.contacts
.update(contactId, {
email: contactData.email,
fields: {
first_name: "Johnny",
last_name: "Smith",
}
})
console.log("Contact updated:", updateResponse.data);
// Delete contact
await client.contacts.delete(contactId);
console.log("Contact deleted");
})
.catch(error => {
console.error("Error in contact lifecycle:", error);
});