0

Add Labels to Source

by
Published Oct 17, 2025

Adds an existing label to a Source. • When called, this endpoint may generate the `Source Modified` event in the audit trail.

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 Labels to Source
8
 * Adds an existing label to a Source.
9

10

11

12
• When called, this endpoint may generate the `Source Modified` event in the audit trail.
13
      
14
 */
15
export async function main(
16
  auth: Segment,
17
  sourceId: string,
18
  body: { labels: { key: string; value: string; description?: string }[] },
19
) {
20
  const url = new URL(`${auth.baseUrl}/sources/${sourceId}/labels`);
21

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