0

Managing the status of the order

Published Apr 8, 2025

Manages the transactional status of the order

Script brevo Verified

The script

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

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