0

List Sources from Tracking Plan

by
Published Oct 17, 2025

Lists Sources connected to a Tracking Plan. • 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. This endpoint requires the user to have at least the following permission(s): * Source Read-only * Tracking Plan Read-only

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
 * List Sources from Tracking Plan
8
 * Lists Sources connected to a Tracking Plan.
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

15
This endpoint requires the user to have at least the following permission(s): 
16
 * Source Read-only
17
 * Tracking Plan Read-only
18
 */
19
export async function main(
20
  auth: Segment,
21
  trackingPlanId: string,
22
  pagination: string | undefined,
23
) {
24
  const url = new URL(
25
    `${auth.baseUrl}/tracking-plans/${trackingPlanId}/sources`,
26
  );
27
  for (const [k, v] of [["pagination", pagination]]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45