Edits history of script submission #20005 for ' Create Source Regulation (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Create Source Regulation
     * 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`
          
     */
    export async function main(
      auth: Segment,
      sourceId: string,
      body: {
        regulationType:
          | "DELETE_ARCHIVE_ONLY"
          | "DELETE_INTERNAL"
          | "DELETE_ONLY"
          | "SUPPRESS_ONLY"
          | "SUPPRESS_WITH_DELETE"
          | "SUPPRESS_WITH_DELETE_INTERNAL"
          | "UNSUPPRESS";
        subjectType: "ANONYMOUS_ID" | "USER_ID";
        subjectIds: string[];
      },
    ) {
      const url = new URL(
        `${auth.baseUrl}/regulations/sources/${sourceId}`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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