0

List product groups

by
Published Dec 20, 2024

Get a list of product groups for a given Catalogs Feed Id owned by the "operation user_account". - By default, the "operation user_account" is the token user_account. Optional: Business Access: Specify an ad_account_id (obtained via List ad accounts) to use the owner of that ad_account as the "operation user_account". In order to do this, the token user_account must have one of the following Business Access roles on the ad_account: Owner, Admin, Catalogs Manager. Learn more

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * List product groups
7
 * Get a list of product groups for a given Catalogs Feed Id owned by the "operation user_account".
8
- By default, the "operation user_account" is the token user_account.
9

10
Optional: Business Access: Specify an ad_account_id (obtained via List ad accounts) to use the owner of that ad_account as the "operation user_account". In order to do this, the token user_account must have one of the following Business Access roles on the ad_account: Owner, Admin, Catalogs Manager.
11

12
Learn more
13
 */
14
export async function main(
15
  auth: Pinterest,
16
  id: string | undefined,
17
  feed_id: string | undefined,
18
  catalog_id: string | undefined,
19
  bookmark: string | undefined,
20
  page_size: string | undefined,
21
  ad_account_id: string | undefined,
22
) {
23
  const url = new URL(`https://api.pinterest.com/v5/catalogs/product_groups`);
24
  for (const [k, v] of [
25
    ["id", id],
26
    ["feed_id", feed_id],
27
    ["catalog_id", catalog_id],
28
    ["bookmark", bookmark],
29
    ["page_size", page_size],
30
    ["ad_account_id", ad_account_id],
31
  ]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "GET",
38
    headers: {
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: undefined,
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49