Update placement 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
		placement?:
11
			| 'GOOGLE_SEARCH_NETWORK'
12
			| 'FACEBOOK_TIMELINE'
13
			| 'GOOGLE_DISPLAY_NETWORK'
14
			| 'FACEBOOK_AUDIENCE_NETWORK'
15
			| 'YOUTUBE'
16
			| 'INSTAGRAM_TIMELINE'
17
			| 'GOOGLE_SHOPPING'
18
			| 'FACEBOOK_MESSENGER'
19
			| 'LINKEDIN_CONTENT'
20
			| 'LINKEDIN_TEXT'
21
			| 'LINKEDIN_INMAIL'
22
			| 'LINKEDIN_DYNAMIC'
23
			| 'FACEBOOK_STORIES'
24
			| 'FACEBOOK_INSTANT_ARTICLES'
25
			| 'FACEBOOK_RIGHT_HAND_COLUMN'
26
			| 'FACEBOOK_MARKETPLACE'
27
			| 'INSTAGRAM_STORIES'
28
			| 'FACEBOOK_MESSENGER_STORIES'
29
			| 'FACEBOOK_SEARCH'
30
			| 'FACEBOOK_INSTREAM_VIDEO'
31
			| 'FACEBOOK_REELS'
32
			| 'INSTAGRAM_EXPLORE_HOME'
33
			| 'INSTAGRAM_PROFILE_FEED'
34
			| 'INSTAGRAM_PROFILE_REELS'
35
			| 'LINKEDIN_AUDIENCE_NETWORK'
36
			| 'TWITTER_ALL'
37
			| 'TWITTER_PUBLISHER_NETWORK'
38
			| 'TWITTER_SEARCH'
39
			| 'TWITTER_TIMELINE'
40
			| 'TWITTER_PROFILE'
41
			| 'GOOGLE_MY_BUSINESS'
42
			| 'FACEBOOK_UNKNOWN'
43
			| 'FACEBOOK_VIDEO_FEED'
44
			| 'INSTAGRAM_REELS'
45
			| 'INSTAGRAM_SHOP'
46
			| 'INSTAGRAM_EXPLORE'
47
			| 'TIKTOK_FEED'
48
			| 'META_AUTOMATIC'
49
		status?:
50
			| 'IS_RUNNING'
51
			| 'STOP'
52
			| 'IN_REVIEW'
53
			| 'REMOVED'
54
			| 'COMPLETED'
55
			| 'DISAPPROVED'
56
			| 'IS_STOPPING'
57
	}
58
) {
59
	const url = new URL(`https://app.adhook.io/v1/promotions/${id}/placementStatistic/status`)
60

61
	const response = await fetch(url, {
62
		method: 'PUT',
63
		headers: {
64
			Authorization: `Bearer ${auth.token}`,
65
			'Content-Type': 'application/json'
66
		},
67
		body: JSON.stringify(body)
68
	})
69

70
	if (!response.ok) {
71
		const text = await response.text()
72
		throw new Error(`${response.status} ${text}`)
73
	}
74

75
	return await response.text()
76
}
77