0

Get insertion order status by ad account id.

by
Published Dec 20, 2024

Get insertion order status for account id ad_account_id. - The token's user_account must either be the Owner of the specified ad account, or have one of the necessary roles granted to them via Business Access: Admin, Finance, Campaign.

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 insertion order status by ad account id.
7
 * Get insertion order status for account id ad_account_id.
8
- The token's user_account must either be the Owner of the specified ad account, or have one of the necessary roles granted to them via Business Access: Admin, Finance, Campaign.
9
 */
10
export async function main(
11
  auth: Pinterest,
12
  ad_account_id: string,
13
  bookmark: string | undefined,
14
  page_size: string | undefined,
15
) {
16
  const url = new URL(
17
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ssio/insertion_orders/status`,
18
  );
19
  for (const [k, v] of [
20
    ["bookmark", bookmark],
21
    ["page_size", page_size],
22
  ]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      Authorization: "Bearer " + auth.token,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40