0

Create orders in batch

by
Published Apr 8, 2025

Create multiple orders at one time instead of one order at a time

Script brevo Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Brevo = {
3
  apiKey: string;
4
};
5
/**
6
 * Create orders in batch
7
 * Create multiple orders at one time instead of one order at a time
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    orders: {
13
      id: string;
14
      createdAt: string;
15
      updatedAt: string;
16
      status: string;
17
      amount: number;
18
      storeId?: string;
19
      identifiers?: {
20
        ext_id?: string;
21
        loyalty_subscription_id?: string;
22
        phone_id?: string;
23
        email_id?: string;
24
      };
25
      products: {
26
        productId: string;
27
        quantity: number;
28
        variantId?: string;
29
        price: number;
30
      }[];
31
      billing?: {
32
        address?: string;
33
        city?: string;
34
        countryCode?: string;
35
        country?: string;
36
        phone?: string;
37
        postCode?: string;
38
        paymentMethod?: string;
39
        region?: string;
40
      };
41
      coupons?: string[];
42
    }[];
43
    notifyUrl?: string;
44
    historical?: false | true;
45
  },
46
) {
47
  const url = new URL(`https://api.brevo.com/v3/orders/status/batch`);
48

49
  const response = await fetch(url, {
50
    method: "POST",
51
    headers: {
52
      "Content-Type": "application/json",
53
      "api-key": auth.apiKey,
54
    },
55
    body: JSON.stringify(body),
56
  });
57
  if (!response.ok) {
58
    const text = await response.text();
59
    throw new Error(`${response.status} ${text}`);
60
  }
61
  return await response.json();
62
}
63