0

Create a new asset group.

by
Published Dec 20, 2024

Create a new asset group with the specified parameters. - An asset group is a custom group of assets based on how you’d like to manage your accounts.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Create a new asset group.
7
 * Create a new asset group with the specified parameters.
8
- An asset group is a custom group of assets based on how you’d like to manage your accounts.
9
 */
10
export async function main(
11
  auth: Pinterest,
12
  business_id: string,
13
  body: {
14
    asset_group_name: string;
15
    asset_group_description: string;
16
    asset_group_types:
17
      | "BRAND"
18
      | "LOCATION_OR_LANGUAGE"
19
      | "PRODUCT_LINE"
20
      | "OTHER"[];
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.pinterest.com/v5/businesses/${business_id}/asset_groups`,
25
  );
26

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