0

Create Cloud Source Regulation

by
Published Oct 17, 2025

Creates a Source-scoped regulation. Please Note: Suppression rules at the Workspace level take precedence over those at the Source level. If a user has been suppressed at the Workspace level, any attempt to un-suppress at the Source level is not supported and the processing of the request will fail in Segment 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 Cloud Source Regulation
8
 * Creates a Source-scoped regulation. 
9

10
 Please Note: Suppression rules at the Workspace level take precedence over those at the Source level. If a user has been suppressed at the Workspace level, any attempt to un-suppress at the Source level is not supported and the processing of the request will fail in Segment
11

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

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