0

List Delivery Metrics Summary from Destination

by
Published Oct 17, 2025

Get an event delivery metrics summary from a Destination. Based on the granularity chosen, there are restrictions on the time range you can query: **Minute**: - Max time range: 4 hours - Oldest possible start time: 48 hours in the past **Hour**: - Max Time range: 7 days - Oldest possible start time: 7 days in the past **Day**: - Max time range: 14 days - Oldest possible start time: 14 days in the past

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * List Delivery Metrics Summary from Destination
8
 * Get an event delivery metrics summary from a Destination.
9

10
Based on the granularity chosen, there are restrictions on the time range you can query:
11

12
**Minute**:
13
- Max time range: 4 hours
14
- Oldest possible start time: 48 hours in the past
15

16
**Hour**:
17
- Max Time range: 7 days
18
- Oldest possible start time: 7 days in the past
19

20
**Day**:
21
- Max time range: 14 days
22
- Oldest possible start time: 14 days in the past
23
 */
24
export async function main(
25
  auth: Segment,
26
  destinationId: string,
27
  sourceId: string | undefined,
28
  startTime: string | undefined,
29
  endTime: string | undefined,
30
  granularity: "DAY" | "HOUR" | "MINUTE" | undefined,
31
) {
32
  const url = new URL(
33
    `${auth.baseUrl}/destinations/${destinationId}/delivery-metrics`,
34
  );
35
  for (const [k, v] of [
36
    ["sourceId", sourceId],
37
    ["startTime", startTime],
38
    ["endTime", endTime],
39
    ["granularity", granularity],
40
  ]) {
41
    if (v !== undefined && v !== "" && k !== undefined) {
42
      url.searchParams.append(k, v);
43
    }
44
  }
45
  const response = await fetch(url, {
46
    method: "GET",
47
    headers: {
48
      Authorization: "Bearer " + auth.token,
49
    },
50
    body: undefined,
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.text();
57
}
58