0

Update Schema Settings in Source

by
Published Oct 17, 2025

Updates the schema configuration for a Source. If Protocols is not enabled for the Source, any updates to Protocols-specific configurations will not be applied. Config API omitted fields: - `updateMask`

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
 * Update Schema Settings in Source
8
 * Updates the schema configuration for a Source. If Protocols is not enabled for the Source, any updates to Protocols-specific configurations will not be applied.
9

10
      Config API omitted fields:
11
- `updateMask`
12
      
13
 */
14
export async function main(
15
  auth: Segment,
16
  sourceId: string,
17
  body: {
18
    track?: {
19
      allowUnplannedEvents?: false | true;
20
      allowUnplannedEventProperties?: false | true;
21
      allowEventOnViolations?: false | true;
22
      allowPropertiesOnViolations?: false | true;
23
      commonEventOnViolations?: "ALLOW" | "BLOCK" | "OMIT_PROPERTIES";
24
    };
25
    identify?: {
26
      allowUnplannedTraits?: false | true;
27
      allowTraitsOnViolations?: false | true;
28
      commonEventOnViolations?: "ALLOW" | "BLOCK" | "OMIT_TRAITS";
29
    };
30
    group?: {
31
      allowUnplannedTraits?: false | true;
32
      allowTraitsOnViolations?: false | true;
33
      commonEventOnViolations?: "ALLOW" | "BLOCK" | "OMIT_TRAITS";
34
    };
35
    forwardingViolationsTo?: string;
36
    forwardingBlockedEventsTo?: string;
37
  },
38
) {
39
  const url = new URL(
40
    `${auth.baseUrl}/sources/${sourceId}/settings`,
41
  );
42

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