0

Remove Source from Tracking Plan

by
Published Oct 17, 2025

Disconnects a Source from a Tracking Plan. • When called, this endpoint may generate the `Source Modified` event in the audit trail. • 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
 * Remove Source from Tracking Plan
8
 * Disconnects a Source from a Tracking Plan.
9

10

11

12
• When called, this endpoint may generate the `Source Modified` event in the audit trail.
13

14

15
• 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.
16
 */
17
export async function main(
18
  auth: Segment,
19
  trackingPlanId: string,
20
  sourceId: string | undefined,
21
) {
22
  const url = new URL(
23
    `${auth.baseUrl}/tracking-plans/${trackingPlanId}/sources`,
24
  );
25
  for (const [k, v] of [["sourceId", sourceId]]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "DELETE",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
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