0

Create customer lists

by
Published Dec 20, 2024

Create a customer list from your records(hashed or plain-text email addresses, or hashed MAIDs or IDFAs).

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 customer lists
7
 * Create a customer list from your records(hashed or plain-text email addresses, or hashed MAIDs or IDFAs).
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  ad_account_id: string,
12
  body: {
13
    name: string;
14
    records: string;
15
    list_type?:
16
      | "EMAIL"
17
      | "IDFA"
18
      | "MAID"
19
      | "LR_ID"
20
      | "DLX_ID"
21
      | "HASHED_PINNER_ID";
22
    exceptions?: {};
23
  },
24
) {
25
  const url = new URL(
26
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/customer_lists`,
27
  );
28

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