Edits history of script submission #11608 for ' Change admin user permissions (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Change admin user permissions
     * This endpoint will allow you to change the permissions of Admin users of your Admin account
     */
    export async function main(
      auth: Brevo,
      email: string,
      body: {
        all_features_access: false | true;
        privileges: {
          feature?:
            | "user_management"
            | "api"
            | "my_plan"
            | "apps_management"
            | "analytics"
            | "sub_organization_groups"
            | "create_sub_organizations"
            | "manage_sub_organizations"
            | "security";
          permissions?:
            | "all"
            | "none"
            | "create"
            | "edit_delete"
            | "create_alerts"
            | "download_data"
            | "my_looks"
            | "explore_create"[];
        }[];
      },
    ) {
      const url = new URL(
        `https://api.brevo.com/v3/corporate/user/${email}/permissions`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          "api-key": auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago