0

Create Filter for Destination

by
Published Oct 17, 2025

Creates a filter in a Destination. • When called, this endpoint may generate the `Destination Filter Created` event in the audit trail.

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
 * Create Filter for Destination
8
 * Creates a filter in a Destination.
9

10

11

12
• When called, this endpoint may generate the `Destination Filter Created` event in the audit trail.
13
      
14
 */
15
export async function main(
16
  auth: Segment,
17
  destinationId: string,
18
  body: {
19
    sourceId: string;
20
    if: string;
21
    actions: {
22
      type: "ALLOW_PROPERTIES" | "DROP" | "DROP_PROPERTIES" | "SAMPLE";
23
      fields?: {};
24
      percent?: number;
25
      path?: string;
26
    }[];
27
    title: string;
28
    description?: string;
29
    enabled: false | true;
30
  },
31
) {
32
  const url = new URL(
33
    `${auth.baseUrl}/destination/${destinationId}/filters`,
34
  );
35

36
  const response = await fetch(url, {
37
    method: "POST",
38
    headers: {
39
      "Content-Type": "application/json",
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: JSON.stringify(body),
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50