Edits history of script submission #11823 for ' Send invitation to an admin user (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Send invitation to an admin user
     * `This endpoint allows you to invite a member to manage the Admin account
    
    Features and their respective permissions are as below:
    
    - `my_plan`:
      - "all"
    - `api`:
      - "none"
    - `user_management`:
      - "all"
    - `app_management` | Not available in ENTv2:
      - "all"
    - `sub_organization_groups`
      - "create"
      - "edit_delete"
    - `create_sub_organizations`
      - "all"
    - `manage_sub_organizations`
      - "all"
    - `analytics`
      - "download_data"
      - "create_alerts"
      - "my_looks"
      - "explore_create"
    - `security`
      - "all"
    
    **Note**:
    - If `all_features_access: false` then only privileges are required otherwise if `true` then it's assumed that all permissions will be there for the invited admin user.
     */
    export async function main(
      auth: Brevo,
      body: {
        email: string;
        all_features_access: false | true;
        groupIds?: string[];
        privileges: {
          feature?:
            | "my_plan"
            | "api"
            | "user_management"
            | "app_management"
            | "sub_organization_groups"
            | "create_sub_organizations"
            | "manage_sub_organizations"
            | "analytics"
            | "security";
          permissions?:
            | "all"
            | "none"
            | "create"
            | "edit_delete"
            | "download_data"
            | "create_alerts"[];
        }[];
      },
    ) {
      const url = new URL(
        `https://api.brevo.com/v3/corporate/user/invitation/send`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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.json();
    }
    

    Submitted by hugo697 428 days ago