Update ad status

Script adhook Verified

by hugo697 ยท 12/20/2024

The script

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

579
	const response = await fetch(url, {
580
		method: 'PUT',
581
		headers: {
582
			Authorization: `Bearer ${auth.token}`,
583
			'Content-Type': 'application/json'
584
		},
585
		body: JSON.stringify(body)
586
	})
587

588
	if (!response.ok) {
589
		const text = await response.text()
590
		throw new Error(`${response.status} ${text}`)
591
	}
592

593
	return await response.text()
594
}
595