Edits history of script submission #11646 for ' Create orders in batch (brevo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Brevo = {
      apiKey: string;
    };
    /**
     * Create orders in batch
     * Create multiple orders at one time instead of one order at a time
     */
    export async function main(
      auth: Brevo,
      body: {
        orders: {
          id: string;
          createdAt: string;
          updatedAt: string;
          status: string;
          amount: number;
          storeId?: string;
          identifiers?: {
            ext_id?: string;
            loyalty_subscription_id?: string;
            phone_id?: string;
            email_id?: string;
          };
          products: {
            productId: string;
            quantity: number;
            variantId?: string;
            price: number;
          }[];
          billing?: {
            address?: string;
            city?: string;
            countryCode?: string;
            country?: string;
            phone?: string;
            postCode?: string;
            paymentMethod?: string;
            region?: string;
          };
          coupons?: string[];
        }[];
        notifyUrl?: string;
        historical?: false | true;
      },
    ) {
      const url = new URL(`https://api.brevo.com/v3/orders/status/batch`);
    
      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