-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy patheverything.ts
More file actions
100 lines (90 loc) · 2.46 KB
/
everything.ts
File metadata and controls
100 lines (90 loc) · 2.46 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { MailtrapClient } from "mailtrap";
const TOKEN = "<YOUR-TOKEN-HERE>";
const ACCOUNT_ID = 123456;
const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID });
const statsClient = client.stats;
const testGetStats = async () => {
try {
const result = await statsClient.get({
start_date: "2026-01-01",
end_date: "2026-01-31",
});
console.log("Stats:", JSON.stringify(result, null, 2));
} catch (error) {
console.error(error);
}
};
const testGetStatsWithFilters = async () => {
try {
const result = await statsClient.get({
start_date: "2026-01-01",
end_date: "2026-01-31",
sending_domain_ids: [1, 2],
sending_streams: ["transactional"],
categories: ["Welcome email"],
email_service_providers: ["Gmail", "Yahoo"],
});
console.log("Filtered stats:", JSON.stringify(result, null, 2));
} catch (error) {
console.error(error);
}
};
const testGetStatsByDomains = async () => {
try {
const result = await statsClient.byDomain({
start_date: "2026-01-01",
end_date: "2026-01-31",
});
console.log("Stats by domains:", JSON.stringify(result, null, 2));
} catch (error) {
console.error(error);
}
};
const testGetStatsByCategories = async () => {
try {
const result = await statsClient.byCategory({
start_date: "2026-01-01",
end_date: "2026-01-31",
});
console.log("Stats by categories:", JSON.stringify(result, null, 2));
} catch (error) {
console.error(error);
}
};
const testGetStatsByEmailServiceProviders = async () => {
try {
const result = await statsClient.byEmailServiceProvider({
start_date: "2026-01-01",
end_date: "2026-01-31",
});
console.log(
"Stats by email service providers:",
JSON.stringify(result, null, 2)
);
} catch (error) {
console.error(error);
}
};
const testGetStatsByDate = async () => {
try {
const result = await statsClient.byDate({
start_date: "2026-01-01",
end_date: "2026-01-31",
});
console.log("Stats by date:", JSON.stringify(result, null, 2));
} catch (error) {
console.error(error);
}
};
(async () => {
try {
await testGetStats();
await testGetStatsWithFilters();
await testGetStatsByDomains();
await testGetStatsByCategories();
await testGetStatsByEmailServiceProviders();
await testGetStatsByDate();
} catch (error) {
console.error("Error running stats examples:", error);
}
})();