0

Create products in batch

by
Published Apr 8, 2025
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 products in batch
7
 *
8
 */
9
export async function main(
10
  auth: Brevo,
11
  body: {
12
    products: {
13
      id: string;
14
      name: string;
15
      url?: string;
16
      imageUrl?: string;
17
      sku?: string;
18
      price?: number;
19
      categories?: string[];
20
      parentId?: string;
21
      metaInfo?: {};
22
      deletedAt?: string;
23
      isDeleted?: false | true;
24
    }[];
25
    updateEnabled?: false | true;
26
  },
27
) {
28
  const url = new URL(`https://api.brevo.com/v3/products/batch`);
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "Content-Type": "application/json",
34
      "api-key": auth.apiKey,
35
    },
36
    body: JSON.stringify(body),
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44