0
Modify ad
One script reply has been approved by the moderators Verified
Created by hugo697 14 days ago Viewed 1228 times
0
Submitted by hugo697 Bun
Verified 14 days ago
1
//native
2
type Adhook = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Adhook,
8
	id: string,
9
	body: {
10
		adStatisticId?: string
11
		modifiedAd?: {
12
			adId?: string
13
			feedItemId?: string
14
			businessName?: string
15
			longTitle?: string
16
			searchAdType?: 'EXPANDED' | 'RESPONSIVE'
17
			textType?: 'SHORT' | 'LONG'
18
			textAdType?:
19
				| 'TEXT_AD'
20
				| 'DYNAMIC_TEXT_AD'
21
				| 'CLICK_TO_CALL_AD'
22
				| 'SHOPPING_AD'
23
				| 'SHOPPING_SHOWCASE_AD'
24
			slides?: {
25
				description?: string
26
				link?: string
27
				title?: string
28
				image?: {
29
					thumbnailUrl?: string
30
					url?: string
31
					croppedUrl?: string
32
					croppedImageSize?: number
33
					croppedWidth?: number
34
					croppedHeight?: number
35
					facebookImageUrl?: string
36
					tikTokImageId?: string
37
					tags?: { x?: number; y?: number; name?: string }[]
38
					productTags?: {
39
						x?: number
40
						y?: number
41
						productId?: string
42
						productName?: string
43
					}[]
44
					link?: string
45
					linkTitle?: string
46
					linkDescription?: string
47
					order?: number
48
				}
49
				video?: {
50
					url?: string
51
					size?: number
52
					fileExtension?: string
53
					facebookVideoId?: string
54
					tikTokVideoId?: string
55
					width?: number
56
					height?: number
57
					thumbnailImage?: {
58
						thumbnailUrl?: string
59
						url?: string
60
						croppedUrl?: string
61
						croppedImageSize?: number
62
						croppedWidth?: number
63
						croppedHeight?: number
64
						facebookImageUrl?: string
65
						tikTokImageId?: string
66
						tags?: { x?: number; y?: number; name?: string }[]
67
						productTags?: {
68
							x?: number
69
							y?: number
70
							productId?: string
71
							productName?: string
72
						}[]
73
						link?: string
74
						linkTitle?: string
75
						linkDescription?: string
76
						order?: number
77
					}
78
					thumbnailTimePosition?: number
79
					cutStartTimePosition?: number
80
					cutEndTimePosition?: number
81
					cutUrl?: string
82
					mediaStatus?: 'READY' | 'PROCESSING' | 'DELETED'
83
					mediaVideoId?: string
84
					title?: string
85
					order?: number
86
					fileName?: string
87
					productTags?: {
88
						x?: number
89
						y?: number
90
						productId?: string
91
						productName?: string
92
					}[]
93
				}
94
				callToAction?:
95
					| 'APPLY_NOW'
96
					| 'BOOK_NOW'
97
					| 'CONTACT_US'
98
					| 'DOWNLOAD'
99
					| 'MORE_OF_THIS'
100
					| 'SHOP_NOW'
101
					| 'ORDER_NOW'
102
					| 'REGISTER'
103
					| 'WATCH_MORE'
104
					| 'NO_BUTTON'
105
					| 'CALL_NOW'
106
					| 'SUBSCRIBE'
107
					| 'GET_QUOTE'
108
					| 'GET_OFFER'
109
					| 'LEARN_MORE'
110
					| 'SIGN_UP'
111
					| 'JOIN'
112
					| 'ATTEND'
113
					| 'REQUEST_DEMO'
114
					| 'LISTEN_NOW'
115
					| 'GET_SHOWTIMES'
116
					| 'UNLOCK_FULL_DOCUMENT'
117
				utmTracking?: {
118
					utmSource?: string
119
					utmMedium?: string
120
					utmCampaign?: string
121
					utmTerm?: string
122
					utmContent?: string
123
					customParams?: string
124
				}
125
			}[]
126
			facebookPage?: {
127
				pictureUrl?: string
128
				name?: string
129
				id?: string
130
				search?: string
131
			}
132
			twitterUser?: {
133
				pictureUrl?: string
134
				name?: string
135
				id?: string
136
				search?: string
137
			}
138
			titles?: string[]
139
			pinnedTitles?: {
140
				textAssetIndex?: number
141
				position?: 'NOT_PINNED' | 'POSITION_1' | 'POSITION_2' | 'POSITION_3'
142
			}[]
143
			title?: string
144
			title2?: string
145
			title3?: string
146
			descriptions?: string[]
147
			pinnedDescriptions?: {
148
				textAssetIndex?: number
149
				position?: 'NOT_PINNED' | 'POSITION_1' | 'POSITION_2' | 'POSITION_3'
150
			}[]
151
			description?: string
152
			description2?: string
153
			dynamicAdDescription1?: string
154
			dynamicAdDescription2?: string
155
			image?: {
156
				thumbnailUrl?: string
157
				url?: string
158
				croppedUrl?: string
159
				croppedImageSize?: number
160
				croppedWidth?: number
161
				croppedHeight?: number
162
				facebookImageUrl?: string
163
				tikTokImageId?: string
164
				tags?: { x?: number; y?: number; name?: string }[]
165
				productTags?: {
166
					x?: number
167
					y?: number
168
					productId?: string
169
					productName?: string
170
				}[]
171
				link?: string
172
				linkTitle?: string
173
				linkDescription?: string
174
				order?: number
175
			}
176
			squareImage?: {
177
				thumbnailUrl?: string
178
				url?: string
179
				croppedUrl?: string
180
				croppedImageSize?: number
181
				croppedWidth?: number
182
				croppedHeight?: number
183
				facebookImageUrl?: string
184
				tikTokImageId?: string
185
				tags?: { x?: number; y?: number; name?: string }[]
186
				productTags?: {
187
					x?: number
188
					y?: number
189
					productId?: string
190
					productName?: string
191
				}[]
192
				link?: string
193
				linkTitle?: string
194
				linkDescription?: string
195
				order?: number
196
			}
197
			verticalImage?: {
198
				thumbnailUrl?: string
199
				url?: string
200
				croppedUrl?: string
201
				croppedImageSize?: number
202
				croppedWidth?: number
203
				croppedHeight?: number
204
				facebookImageUrl?: string
205
				tikTokImageId?: string
206
				tags?: { x?: number; y?: number; name?: string }[]
207
				productTags?: {
208
					x?: number
209
					y?: number
210
					productId?: string
211
					productName?: string
212
				}[]
213
				link?: string
214
				linkTitle?: string
215
				linkDescription?: string
216
				order?: number
217
			}
218
			video?: {
219
				url?: string
220
				size?: number
221
				fileExtension?: string
222
				facebookVideoId?: string
223
				tikTokVideoId?: string
224
				width?: number
225
				height?: number
226
				thumbnailImage?: {
227
					thumbnailUrl?: string
228
					url?: string
229
					croppedUrl?: string
230
					croppedImageSize?: number
231
					croppedWidth?: number
232
					croppedHeight?: number
233
					facebookImageUrl?: string
234
					tikTokImageId?: string
235
					tags?: { x?: number; y?: number; name?: string }[]
236
					productTags?: {
237
						x?: number
238
						y?: number
239
						productId?: string
240
						productName?: string
241
					}[]
242
					link?: string
243
					linkTitle?: string
244
					linkDescription?: string
245
					order?: number
246
				}
247
				thumbnailTimePosition?: number
248
				cutStartTimePosition?: number
249
				cutEndTimePosition?: number
250
				cutUrl?: string
251
				mediaStatus?: 'READY' | 'PROCESSING' | 'DELETED'
252
				mediaVideoId?: string
253
				title?: string
254
				order?: number
255
				fileName?: string
256
				productTags?: {
257
					x?: number
258
					y?: number
259
					productId?: string
260
					productName?: string
261
				}[]
262
			}
263
			verticalVideo?: {
264
				url?: string
265
				size?: number
266
				fileExtension?: string
267
				facebookVideoId?: string
268
				tikTokVideoId?: string
269
				width?: number
270
				height?: number
271
				thumbnailImage?: {
272
					thumbnailUrl?: string
273
					url?: string
274
					croppedUrl?: string
275
					croppedImageSize?: number
276
					croppedWidth?: number
277
					croppedHeight?: number
278
					facebookImageUrl?: string
279
					tikTokImageId?: string
280
					tags?: { x?: number; y?: number; name?: string }[]
281
					productTags?: {
282
						x?: number
283
						y?: number
284
						productId?: string
285
						productName?: string
286
					}[]
287
					link?: string
288
					linkTitle?: string
289
					linkDescription?: string
290
					order?: number
291
				}
292
				thumbnailTimePosition?: number
293
				cutStartTimePosition?: number
294
				cutEndTimePosition?: number
295
				cutUrl?: string
296
				mediaStatus?: 'READY' | 'PROCESSING' | 'DELETED'
297
				mediaVideoId?: string
298
				title?: string
299
				order?: number
300
				fileName?: string
301
				productTags?: {
302
					x?: number
303
					y?: number
304
					productId?: string
305
					productName?: string
306
				}[]
307
			}
308
			images?: {
309
				thumbnailUrl?: string
310
				url?: string
311
				croppedUrl?: string
312
				croppedImageSize?: number
313
				croppedWidth?: number
314
				croppedHeight?: number
315
				facebookImageUrl?: string
316
				tikTokImageId?: string
317
				tags?: { x?: number; y?: number; name?: string }[]
318
				productTags?: {
319
					x?: number
320
					y?: number
321
					productId?: string
322
					productName?: string
323
				}[]
324
				link?: string
325
				linkTitle?: string
326
				linkDescription?: string
327
				order?: number
328
			}[]
329
			squareImages?: {
330
				thumbnailUrl?: string
331
				url?: string
332
				croppedUrl?: string
333
				croppedImageSize?: number
334
				croppedWidth?: number
335
				croppedHeight?: number
336
				facebookImageUrl?: string
337
				tikTokImageId?: string
338
				tags?: { x?: number; y?: number; name?: string }[]
339
				productTags?: {
340
					x?: number
341
					y?: number
342
					productId?: string
343
					productName?: string
344
				}[]
345
				link?: string
346
				linkTitle?: string
347
				linkDescription?: string
348
				order?: number
349
			}[]
350
			logos?: {
351
				thumbnailUrl?: string
352
				url?: string
353
				croppedUrl?: string
354
				croppedImageSize?: number
355
				croppedWidth?: number
356
				croppedHeight?: number
357
				facebookImageUrl?: string
358
				tikTokImageId?: string
359
				tags?: { x?: number; y?: number; name?: string }[]
360
				productTags?: {
361
					x?: number
362
					y?: number
363
					productId?: string
364
					productName?: string
365
				}[]
366
				link?: string
367
				linkTitle?: string
368
				linkDescription?: string
369
				order?: number
370
			}[]
371
			squareLogos?: {
372
				thumbnailUrl?: string
373
				url?: string
374
				croppedUrl?: string
375
				croppedImageSize?: number
376
				croppedWidth?: number
377
				croppedHeight?: number
378
				facebookImageUrl?: string
379
				tikTokImageId?: string
380
				tags?: { x?: number; y?: number; name?: string }[]
381
				productTags?: {
382
					x?: number
383
					y?: number
384
					productId?: string
385
					productName?: string
386
				}[]
387
				link?: string
388
				linkTitle?: string
389
				linkDescription?: string
390
				order?: number
391
			}[]
392
			videos?: {
393
				url?: string
394
				size?: number
395
				fileExtension?: string
396
				facebookVideoId?: string
397
				tikTokVideoId?: string
398
				width?: number
399
				height?: number
400
				thumbnailImage?: {
401
					thumbnailUrl?: string
402
					url?: string
403
					croppedUrl?: string
404
					croppedImageSize?: number
405
					croppedWidth?: number
406
					croppedHeight?: number
407
					facebookImageUrl?: string
408
					tikTokImageId?: string
409
					tags?: { x?: number; y?: number; name?: string }[]
410
					productTags?: {
411
						x?: number
412
						y?: number
413
						productId?: string
414
						productName?: string
415
					}[]
416
					link?: string
417
					linkTitle?: string
418
					linkDescription?: string
419
					order?: number
420
				}
421
				thumbnailTimePosition?: number
422
				cutStartTimePosition?: number
423
				cutEndTimePosition?: number
424
				cutUrl?: string
425
				mediaStatus?: 'READY' | 'PROCESSING' | 'DELETED'
426
				mediaVideoId?: string
427
				title?: string
428
				order?: number
429
				fileName?: string
430
				productTags?: {
431
					x?: number
432
					y?: number
433
					productId?: string
434
					productName?: string
435
				}[]
436
			}[]
437
			youTubeVideos?: { url?: string; id?: string }[]
438
			link?: string
439
			displayLink?: string
440
			linkDescription?: string
441
			utmLink?: string
442
			channelReferenceLink?: string
443
			callToAction?:
444
				| 'APPLY_NOW'
445
				| 'BOOK_NOW'
446
				| 'CONTACT_US'
447
				| 'DOWNLOAD'
448
				| 'MORE_OF_THIS'
449
				| 'SHOP_NOW'
450
				| 'ORDER_NOW'
451
				| 'REGISTER'
452
				| 'WATCH_MORE'
453
				| 'NO_BUTTON'
454
				| 'CALL_NOW'
455
				| 'SUBSCRIBE'
456
				| 'GET_QUOTE'
457
				| 'GET_OFFER'
458
				| 'LEARN_MORE'
459
				| 'SIGN_UP'
460
				| 'JOIN'
461
				| 'ATTEND'
462
				| 'REQUEST_DEMO'
463
				| 'LISTEN_NOW'
464
				| 'GET_SHOWTIMES'
465
				| 'UNLOCK_FULL_DOCUMENT'
466
			displayLinkPath?: { path1?: string; path2?: string }
467
			phoneNumber?: string
468
			countryCode?: string
469
			callOnlyDescription1?: string
470
			callOnlyDescription2?: string
471
			facebookPostId?: string
472
			instagramPostId?: string
473
			twitterTweetId?: string
474
			linkedInPostId?: string
475
			tikTokPostId?: string
476
			carouselMultiShareEndCard?: false | true
477
			carouselMultiShareOptimized?: false | true
478
			facebookInstantExperienceId?: string
479
			facebookInstantExperienceThumbnails?: {
480
				elementId?: string
481
				photoId?: string
482
				height?: number
483
				width?: number
484
				cropTopLeft?: number[]
485
				cropBottomRight?: number[]
486
			}[]
487
			tikTokProfileName?: string
488
			tikTokProfileImage?: {
489
				thumbnailUrl?: string
490
				url?: string
491
				croppedUrl?: string
492
				croppedImageSize?: number
493
				croppedWidth?: number
494
				croppedHeight?: number
495
				facebookImageUrl?: string
496
				tikTokImageId?: string
497
				tags?: { x?: number; y?: number; name?: string }[]
498
				productTags?: {
499
					x?: number
500
					y?: number
501
					productId?: string
502
					productName?: string
503
				}[]
504
				link?: string
505
				linkTitle?: string
506
				linkDescription?: string
507
				order?: number
508
			}
509
			document?: {
510
				url?: string
511
				fileType?: string
512
				title?: string
513
				size?: number
514
				nbrOfPreviewPages?: number
515
			}
516
			adStatus?:
517
				| 'IS_RUNNING'
518
				| 'STOP'
519
				| 'IN_REVIEW'
520
				| 'REMOVED'
521
				| 'COMPLETED'
522
				| 'DISAPPROVED'
523
				| 'IS_STOPPING'
524
			id?: string
525
			type?: 'SHORT' | 'LONG'
526
		}
527
	}
528
) {
529
	const url = new URL(`https://app.adhook.io/v1/promotions/${id}/adStatistic`)
530

531
	const response = await fetch(url, {
532
		method: 'PUT',
533
		headers: {
534
			Authorization: `Bearer ${auth.token}`,
535
			'Content-Type': 'application/json'
536
		},
537
		body: JSON.stringify(body)
538
	})
539

540
	if (!response.ok) {
541
		const text = await response.text()
542
		throw new Error(`${response.status} ${text}`)
543
	}
544

545
	return await response.json()
546
}
547