0

Create ad account

by
Published Dec 20, 2024

Create a new ad account. Different ad accounts can support different currencies, payment methods, etc. An ad account is needed to create campaigns, ad groups, and ads; other accounts (your employees or partners) can be assigned business access and appropriate roles to access an ad account. You can set up up to 50 ad accounts per user. (The user must have a business account to create an ad account.) For more, see Create an advertiser account.

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 ad account
7
 * Create a new ad account. Different ad accounts can support different currencies, payment methods, etc.
8
An ad account is needed to create campaigns, ad groups, and ads; other accounts (your employees or partners) can be assigned business access and appropriate roles to access an ad account. 
9
You can set up up to 50 ad accounts per user. (The user must have a business account to create an ad account.) 
10
For more, see Create an advertiser account.
11
 */
12
export async function main(
13
  auth: Pinterest,
14
  body: {
15
    country?:
16
      | "AD"
17
      | "AE"
18
      | "AF"
19
      | "AG"
20
      | "AI"
21
      | "AL"
22
      | "AM"
23
      | "AO"
24
      | "AQ"
25
      | "AR"
26
      | "AS"
27
      | "AT"
28
      | "AU"
29
      | "AW"
30
      | "AX"
31
      | "AZ"
32
      | "BA"
33
      | "BB"
34
      | "BD"
35
      | "BE"
36
      | "BF"
37
      | "BG"
38
      | "BH"
39
      | "BI"
40
      | "BJ"
41
      | "BL"
42
      | "BM"
43
      | "BN"
44
      | "BO"
45
      | "BQ"
46
      | "BR"
47
      | "BS"
48
      | "BT"
49
      | "BV"
50
      | "BW"
51
      | "BY"
52
      | "BZ"
53
      | "CA"
54
      | "CC"
55
      | "CD"
56
      | "CF"
57
      | "CG"
58
      | "CH"
59
      | "CI"
60
      | "CK"
61
      | "CL"
62
      | "CM"
63
      | "CN"
64
      | "CO"
65
      | "CR"
66
      | "CU"
67
      | "CV"
68
      | "CW"
69
      | "CX"
70
      | "CY"
71
      | "CZ"
72
      | "DE"
73
      | "DJ"
74
      | "DK"
75
      | "DM"
76
      | "DO"
77
      | "DZ"
78
      | "EC"
79
      | "EE"
80
      | "EG"
81
      | "EH"
82
      | "ER"
83
      | "ES"
84
      | "ET"
85
      | "FI"
86
      | "FJ"
87
      | "FK"
88
      | "FM"
89
      | "FO"
90
      | "FR"
91
      | "GA"
92
      | "GB"
93
      | "GD"
94
      | "GE"
95
      | "GF"
96
      | "GG"
97
      | "GH"
98
      | "GI"
99
      | "GL"
100
      | "GM"
101
      | "GN"
102
      | "GP"
103
      | "GQ"
104
      | "GR"
105
      | "GS"
106
      | "GT"
107
      | "GU"
108
      | "GW"
109
      | "GY"
110
      | "HK"
111
      | "HM"
112
      | "HN"
113
      | "HR"
114
      | "HT"
115
      | "HU"
116
      | "ID"
117
      | "IE"
118
      | "IL"
119
      | "IM"
120
      | "IN"
121
      | "IO"
122
      | "IQ"
123
      | "IR"
124
      | "IS"
125
      | "IT"
126
      | "JE"
127
      | "JM"
128
      | "JO"
129
      | "JP"
130
      | "KE"
131
      | "KG"
132
      | "KH"
133
      | "KI"
134
      | "KM"
135
      | "KN"
136
      | "KR"
137
      | "KW"
138
      | "KY"
139
      | "KZ"
140
      | "LA"
141
      | "LB"
142
      | "LC"
143
      | "LI"
144
      | "LK"
145
      | "LR"
146
      | "LS"
147
      | "LT"
148
      | "LU"
149
      | "LV"
150
      | "LY"
151
      | "MA"
152
      | "MC"
153
      | "MD"
154
      | "ME"
155
      | "MF"
156
      | "MG"
157
      | "MH"
158
      | "MK"
159
      | "ML"
160
      | "MM"
161
      | "MN"
162
      | "MO"
163
      | "MP"
164
      | "MQ"
165
      | "MR"
166
      | "MS"
167
      | "MT"
168
      | "MU"
169
      | "MV"
170
      | "MW"
171
      | "MX"
172
      | "MY"
173
      | "MZ"
174
      | "NA"
175
      | "NC"
176
      | "NE"
177
      | "NF"
178
      | "NG"
179
      | "NI"
180
      | "NL"
181
      | "NO"
182
      | "NP"
183
      | "NR"
184
      | "NU"
185
      | "NZ"
186
      | "OM"
187
      | "PA"
188
      | "PE"
189
      | "PF"
190
      | "PG"
191
      | "PH"
192
      | "PK"
193
      | "PL"
194
      | "PM"
195
      | "PN"
196
      | "PR"
197
      | "PS"
198
      | "PT"
199
      | "PW"
200
      | "PY"
201
      | "QA"
202
      | "RE"
203
      | "RO"
204
      | "RS"
205
      | "RU"
206
      | "RW"
207
      | "SA"
208
      | "SB"
209
      | "SC"
210
      | "SD"
211
      | "SE"
212
      | "SG"
213
      | "SH"
214
      | "SI"
215
      | "SJ"
216
      | "SK"
217
      | "SL"
218
      | "SM"
219
      | "SN"
220
      | "SO"
221
      | "SR"
222
      | "SS"
223
      | "ST"
224
      | "SV"
225
      | "SX"
226
      | "SY"
227
      | "SZ"
228
      | "TC"
229
      | "TD"
230
      | "TF"
231
      | "TG"
232
      | "TH"
233
      | "TJ"
234
      | "TK"
235
      | "TL"
236
      | "TM"
237
      | "TN"
238
      | "TO"
239
      | "TR"
240
      | "TT"
241
      | "TV"
242
      | "TW"
243
      | "TZ"
244
      | "UA"
245
      | "UG"
246
      | "UM"
247
      | "US"
248
      | "UY"
249
      | "UZ"
250
      | "VA"
251
      | "VC"
252
      | "VE"
253
      | "VG"
254
      | "VI"
255
      | "VN"
256
      | "VU"
257
      | "WF"
258
      | "WS"
259
      | "YE"
260
      | "YT"
261
      | "ZA"
262
      | "ZM"
263
      | "ZW";
264
    name?: string;
265
    owner_user_id?: string;
266
  },
267
) {
268
  const url = new URL(`https://api.pinterest.com/v5/ad_accounts`);
269

270
  const response = await fetch(url, {
271
    method: "POST",
272
    headers: {
273
      "Content-Type": "application/json",
274
      Authorization: "Bearer " + auth.token,
275
    },
276
    body: JSON.stringify(body),
277
  });
278
  if (!response.ok) {
279
    const text = await response.text();
280
    throw new Error(`${response.status} ${text}`);
281
  }
282
  return await response.json();
283
}
284