0

Create Label

by
Published Oct 17, 2025

Creates a new label. • When called, this endpoint may generate the `Label Created` event in the audit trail. The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting 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
 * Create Label
8
 * Creates a new label.
9

10

11

12
• When called, this endpoint may generate the `Label Created` event in the audit trail.
13
      
14

15

16
The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
17
 */
18
export async function main(
19
  auth: Segment,
20
  body: { label: { key: string; value: string; description?: string } },
21
) {
22
  const url = new URL(`${auth.baseUrl}/labels`);
23

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