0

Update asset groups.

by
Published Dec 20, 2024

Update a batch of asset groups with the specified parameters.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Update asset groups.
7
 * Update a batch of asset groups with the specified parameters.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  business_id: string,
12
  body: {
13
    asset_groups_to_update?: {
14
      asset_group_id: string;
15
      name?: string;
16
      description?: string;
17
      asset_group_types?:
18
        | "BRAND"
19
        | "LOCATION_OR_LANGUAGE"
20
        | "PRODUCT_LINE"
21
        | "OTHER"[];
22
      assets_to_add?: string[];
23
      assets_to_remove?: string[];
24
    }[];
25
  },
26
) {
27
  const url = new URL(
28
    `https://api.pinterest.com/v5/businesses/${business_id}/asset_groups`,
29
  );
30

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