Edits history of script submission #20011 for ' Create Workspace Regulation (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Create Workspace Regulation
     * Creates a Workspace-scoped regulation.
    
    
    
    • When called, this endpoint may generate the `Workspace Regulation Created` event in the audit trail.
    
    Config API omitted fields:
    - `attributes`,
    - `userAgent`
          
     */
    export async function main(
      auth: Segment,
      body: {
        regulationType:
          | "DELETE_INTERNAL"
          | "DELETE_ONLY"
          | "SUPPRESS_ONLY"
          | "SUPPRESS_WITH_DELETE"
          | "SUPPRESS_WITH_DELETE_INTERNAL"
          | "UNSUPPRESS";
        subjectType: "OBJECT_ID" | "USER_ID";
        subjectIds: string[];
      },
    ) {
      const url = new URL(`${auth.baseUrl}/regulations`);
    
      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