0

Update ads

by
Published Dec 20, 2024

Update multiple existing ads

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 ads
7
 * Update multiple existing ads
8
 */
9
export async function main(
10
  auth: Pinterest,
11
  ad_account_id: string,
12
  body: {
13
    ad_group_id?: string;
14
    android_deep_link?: string;
15
    carousel_android_deep_links?: string[];
16
    carousel_destination_urls?: string[];
17
    carousel_ios_deep_links?: string[];
18
    click_tracking_url?: string;
19
    creative_type?:
20
      | "REGULAR"
21
      | "VIDEO"
22
      | "SHOPPING"
23
      | "CAROUSEL"
24
      | "MAX_VIDEO"
25
      | "SHOP_THE_PIN"
26
      | "COLLECTION"
27
      | "IDEA"
28
      | "SHOWCASE"
29
      | "QUIZ";
30
    destination_url?: string;
31
    ios_deep_link?: string;
32
    is_pin_deleted?: false | true;
33
    is_removable?: false | true;
34
    name?: string;
35
    status?: "ACTIVE" | "PAUSED" | "ARCHIVED" | "DRAFT" | "DELETED_DRAFT";
36
    tracking_urls?: {
37
      impression?: string[];
38
      click?: string[];
39
      engagement?: string[];
40
      buyable_button?: string[];
41
      audience_verification?: string[];
42
    };
43
    view_tracking_url?: string;
44
    lead_form_id?: string;
45
    grid_click_type?: "CLOSEUP" | "DIRECT_TO_DESTINATION";
46
    customizable_cta_type?:
47
      | "GET_OFFER"
48
      | "LEARN_MORE"
49
      | "ORDER_NOW"
50
      | "SHOP_NOW"
51
      | "SIGN_UP"
52
      | "SUBSCRIBE"
53
      | "BUY_NOW"
54
      | "CONTACT_US"
55
      | "GET_QUOTE"
56
      | "VISIT_SITE"
57
      | "APPLY_NOW"
58
      | "BOOK_NOW"
59
      | "REQUEST_DEMO"
60
      | "REGISTER_NOW"
61
      | "FIND_A_DEALER"
62
      | "ADD_TO_CART"
63
      | "WATCH_NOW"
64
      | "READ_MORE";
65
    quiz_pin_data?: {
66
      questions?: {
67
        question_id?: number;
68
        question_text?: string;
69
        options?: { id?: number; text?: string }[];
70
      }[];
71
      results?: {
72
        organic_pin_id?: string;
73
        android_deep_link?: string;
74
        ios_deep_link?: string;
75
        destination_url?: string;
76
        result_id?: number;
77
      }[];
78
      tie_breaker_type?: "RANDOM" | "CUSTOM";
79
      tie_breaker_custom_result?: {
80
        organic_pin_id?: string;
81
        android_deep_link?: string;
82
        ios_deep_link?: string;
83
        destination_url?: string;
84
        result_id?: number;
85
      };
86
    };
87
  } & { id: string; pin_id?: string }[],
88
) {
89
  const url = new URL(
90
    `https://api.pinterest.com/v5/ad_accounts/${ad_account_id}/ads`,
91
  );
92

93
  const response = await fetch(url, {
94
    method: "PATCH",
95
    headers: {
96
      "Content-Type": "application/json",
97
      Authorization: "Bearer " + auth.token,
98
    },
99
    body: JSON.stringify(body),
100
  });
101
  if (!response.ok) {
102
    const text = await response.text();
103
    throw new Error(`${response.status} ${text}`);
104
  }
105
  return await response.json();
106
}
107