Edits history of script submission #11857 for ' Update sub-account plan (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Update sub-account plan
     * This endpoint will update the sub-account plan. On the Corporate solution new version v2, you can set an unlimited number of credits in your sub-organization. Please pass the value “-1" to set the consumable in unlimited mode.
     */
    export async function main(
      auth: Brevo,
      id: string,
      body: {
        credits?: {
          email?: number;
          sms?: number;
          wpSubscribers?: number;
          externalFeeds?: number;
          whatsapp?: number;
        };
        features?: {
          users?: number;
          landingPage?: number;
          inbox?: number;
          salesUsers?: number;
        };
      },
    ) {
      const url = new URL(
        `https://api.brevo.com/v3/corporate/subAccount/${id}/plan`,
      );
    
      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