0

Replace Rules in Tracking Plan

by
Published Oct 17, 2025

Replaces Tracking Plan rules. • In order to successfully call this endpoint, the specified Workspace needs to have the Protocols feature enabled. Please reach out to your customer success manager for more information.

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
 * Replace Rules in Tracking Plan
8
 * Replaces Tracking Plan rules.
9

10

11

12
• In order to successfully call this endpoint, the specified Workspace needs to have the Protocols feature enabled. Please reach out to your customer success manager for more information.
13
 */
14
export async function main(
15
  auth: Segment,
16
  trackingPlanId: string,
17
  body: {
18
    rules: {
19
      type: "COMMON" | "GROUP" | "IDENTIFY" | "PAGE" | "SCREEN" | "TRACK";
20
      key?: string;
21
      jsonSchema: {};
22
      version: number;
23
    }[];
24
  },
25
) {
26
  const url = new URL(
27
    `${auth.baseUrl}/tracking-plans/${trackingPlanId}/rules`,
28
  );
29

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