0

Update Transformation

by
Published Oct 17, 2025

Updates an existing Transformation. • When called, this endpoint may generate the `Transformation Updated` event in the audit trail. • In order to successfully call this endpoint, the specified Workspace needs to have the Protocols feature enabled. Please reach out to your customer success manager 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
 * Update Transformation
8
 * Updates an existing Transformation.
9

10

11

12
• When called, this endpoint may generate the `Transformation Updated` event in the audit trail.
13

14

15
• In order to successfully call this endpoint, the specified Workspace needs to have the Protocols feature enabled. Please reach out to your customer success manager for more information.
16
 */
17
export async function main(
18
  auth: Segment,
19
  transformationId: string,
20
  body: {
21
    name?: string;
22
    sourceId?: string;
23
    destinationMetadataId?: string;
24
    enabled?: false | true;
25
    if?: string;
26
    drop?: false | true;
27
    newEventName?: string;
28
    propertyRenames?: { oldName: string; newName: string }[];
29
    propertyValueTransformations?: {
30
      propertyPaths: string[];
31
      propertyValue: string;
32
    }[];
33
    fqlDefinedProperties?: { fql: string; propertyName: string }[];
34
    allowProperties?: string[];
35
    hashPropertiesConfiguration?: {
36
      algorithm: string;
37
      key?: string;
38
      encoding?: "BASE16" | "BASE64" | "BASE64URL" | "HEX";
39
      paths: string[];
40
    };
41
  },
42
) {
43
  const url = new URL(
44
    `${auth.baseUrl}/transformations/${transformationId}`,
45
  );
46

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