Edits history of script submission #19994 for ' Add Permissions to User Group (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Add Permissions to User Group
     * Adds a list of access permissions to a user group.
    
    
    
    • When called, this endpoint may generate one or more of the following audit trail events:* Policy Created
    * User Group Policy Updated
          
    
    
    The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
     */
    export async function main(
      auth: Segment,
      userGroupId: string,
      body: {
        permissions: {
          roleId: string;
          resources: {
            id: string;
            type: "FUNCTION" | "SOURCE" | "SPACE" | "WAREHOUSE" | "WORKSPACE";
            labels?: { key: string; value: string; description?: string }[];
          }[];
        }[];
      },
    ) {
      const url = new URL(
        `${auth.baseUrl}/groups/${userGroupId}/permissions`,
      );
    
      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