0

Update Filter for Destination

by
Published Oct 17, 2025

Updates a filter in a Destination. • When called, this endpoint may generate one or more of the following audit trail events:* Destination Filter Enabled * Destination Filter Disabled

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

10

11

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

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