0

Get user account

by
Published Dec 20, 2024

Get account information for the "operation user_account" - By default, the "operation user_account" is the token user_account. If using Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account". See Understanding Business Access for more information.

Script pinterest Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Get user account
7
 * Get account information for the "operation user_account"
8
- By default, the "operation user_account" is the token user_account.
9

10
If using Business Access: Specify an ad_account_id to use the owner of that ad_account as the "operation user_account". See Understanding Business Access for more information.
11
 */
12
export async function main(auth: Pinterest, ad_account_id: string | undefined) {
13
  const url = new URL(`https://api.pinterest.com/v5/user_account`);
14
  for (const [k, v] of [["ad_account_id", ad_account_id]]) {
15
    if (v !== undefined && v !== "" && k !== undefined) {
16
      url.searchParams.append(k, v);
17
    }
18
  }
19
  const response = await fetch(url, {
20
    method: "GET",
21
    headers: {
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32