0

Preview Destination Filter

by
Published Oct 17, 2025

Simulates the application of a Destination filter to a provided JSON payload.

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
 * Preview Destination Filter
8
 * Simulates the application of a Destination filter to a provided JSON payload.
9
 */
10
export async function main(
11
  auth: Segment,
12
  body: {
13
    filter: {
14
      if: string;
15
      actions: {
16
        type: "ALLOW_PROPERTIES" | "DROP" | "DROP_PROPERTIES" | "SAMPLE";
17
        fields?: {};
18
        percent?: number;
19
        path?: string;
20
      }[];
21
    };
22
    payload: {};
23
  },
24
) {
25
  const url = new URL(
26
    `${auth.baseUrl}/destination/filters/preview`,
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43