0

Create/Update a product

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

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