0

Create insertion order through SSIO.

by
Published Dec 20, 2024

Create insertion order through SSIO for 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 537 days ago
1
//native
2
type Pinterest = {
3
  token: string;
4
};
5
/**
6
 * Create insertion order through SSIO.
7
 * Create insertion order through SSIO for 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
  body: {
14
    start_date?: string;
15
    end_date?: string;
16
    po_number?: string;
17
    budget_amount?: number;
18
    billing_contact_firstname?: string;
19
    billing_contact_lastname?: string;
20
    billing_contact_email?: string;
21
    media_contact_firstname?: string;
22
    media_contact_lastname?: string;
23
    media_contact_email?: string;
24
    agency_link?: string;
25
    user_email?: string;
26
  } & {
27
    accepted_terms_time?: number;
28
    pmp_id: string;
29
    order_name: string;
30
    order_line_type: "BUDGET" | "PERPETUALS";
31
    accepted_terms_id: string;
32
    billto_company_id: string;
33
    billto_business_address_id: string;
34
    billto_billing_address_id: string;
35
    estimated_monthly_spend?: number;
36
    currency_info:
37
      | "UNK"
38
      | "USD"
39
      | "GBP"
40
      | "CAD"
41
      | "EUR"
42
      | "AUD"
43
      | "NZD"
44
      | "SEK"
45
      | "ILS"
46
      | "CHF"
47
      | "HKD"
48
      | "JPY"
49
      | "SGD"
50
      | "KRW"
51
      | "NOK"
52
      | "DKK"
53
      | "PLN"
54
      | "RON"
55
      | "HUF"
56
      | "CZK"
57
      | "BRL"
58
      | "MXN"
59
      | "ARS"
60
      | "CLP"
61
      | "COP"
62
      | "INR"
63
      | "TRY";
64
  },
65
) {
66
  const url = new URL(
67
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ssio/insertion_orders`,
68
  );
69

70
  const response = await fetch(url, {
71
    method: "POST",
72
    headers: {
73
      "Content-Type": "application/json",
74
      Authorization: "Bearer " + auth.token,
75
    },
76
    body: JSON.stringify(body),
77
  });
78
  if (!response.ok) {
79
    const text = await response.text();
80
    throw new Error(`${response.status} ${text}`);
81
  }
82
  return await response.json();
83
}
84