0

Update customer list

by
Published Dec 20, 2024

Append or remove records to/from an existing customer list.

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 customer list
7
 * Append or remove records to/from an existing customer list.
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  ad_account_id: string,
12
  customer_list_id: string,
13
  body: {
14
    records: string;
15
    operation_type: "ADD" | "REMOVE";
16
    exceptions?: { code?: number; message?: string };
17
  },
18
) {
19
  const url = new URL(
20
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/customer_lists/${customer_list_id}`,
21
  );
22

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