Edits history of script submission #20136 for ' Update Transformation (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Update Transformation
     * 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.
     */
    export async function main(
      auth: Segment,
      transformationId: string,
      body: {
        name?: string;
        sourceId?: string;
        destinationMetadataId?: string;
        enabled?: false | true;
        if?: string;
        drop?: false | true;
        newEventName?: string;
        propertyRenames?: { oldName: string; newName: string }[];
        propertyValueTransformations?: {
          propertyPaths: string[];
          propertyValue: string;
        }[];
        fqlDefinedProperties?: { fql: string; propertyName: string }[];
        allowProperties?: string[];
        hashPropertiesConfiguration?: {
          algorithm: string;
          key?: string;
          encoding?: "BASE16" | "BASE64" | "BASE64URL" | "HEX";
          paths: string[];
        };
      },
    ) {
      const url = new URL(
        `${auth.baseUrl}/transformations/${transformationId}`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago