0

Add Source to Tracking Plan

by
Published Oct 17, 2025

Connects a Source to 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
 * Add Source to Tracking Plan
8
 * Connects a Source to 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
  body: { sourceId: string },
21
) {
22
  const url = new URL(
23
    `${auth.baseUrl}/tracking-plans/${trackingPlanId}/sources`,
24
  );
25

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