0

Create Workspace Regulation

by
Published Oct 17, 2025

Creates a Workspace-scoped regulation. • When called, this endpoint may generate the `Workspace Regulation Created` event in the audit trail. Config API omitted fields: - `attributes`, - `userAgent`

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 Workspace Regulation
8
 * Creates a Workspace-scoped regulation.
9

10

11

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

14
Config API omitted fields:
15
- `attributes`,
16
- `userAgent`
17
      
18
 */
19
export async function main(
20
  auth: Segment,
21
  body: {
22
    regulationType:
23
      | "DELETE_INTERNAL"
24
      | "DELETE_ONLY"
25
      | "SUPPRESS_ONLY"
26
      | "SUPPRESS_WITH_DELETE"
27
      | "SUPPRESS_WITH_DELETE_INTERNAL"
28
      | "UNSUPPRESS";
29
    subjectType: "OBJECT_ID" | "USER_ID";
30
    subjectIds: string[];
31
  },
32
) {
33
  const url = new URL(`${auth.baseUrl}/regulations`);
34

35
  const response = await fetch(url, {
36
    method: "POST",
37
    headers: {
38
      "Content-Type": "application/json",
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49