0

Create 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 • When called, this endpoint may generate the `Source 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 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

13

14
• When called, this endpoint may generate the `Source Regulation Created` event in the audit trail.
15

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

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