0
Update promotion budget settings
One script reply has been approved by the moderators Verified
Created by hugo697 16 days ago Viewed 1421 times
0
Submitted by hugo697 Bun
Verified 16 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
		budgetChannels?: {
11
			channel?:
12
				| 'FACEBOOK'
13
				| 'INSTAGRAM'
14
				| 'GOOGLE_ADWORDS'
15
				| 'GOOGLE_DISPLAY_NETWORK'
16
				| 'GOOGLE_ANALYTICS'
17
				| 'YOUTUBE'
18
				| 'XING'
19
				| 'LINKED_IN'
20
				| 'TWITTER'
21
				| 'GOOGLE_MY_BUSINESS'
22
				| 'TIKTOK'
23
				| 'BITLY'
24
			placement?:
25
				| 'GOOGLE_DISPLAY_NETWORK'
26
				| 'YOUTUBE'
27
				| 'GOOGLE_MY_BUSINESS'
28
				| 'GOOGLE_SEARCH_NETWORK'
29
				| 'FACEBOOK_TIMELINE'
30
				| 'FACEBOOK_AUDIENCE_NETWORK'
31
				| 'INSTAGRAM_TIMELINE'
32
				| 'GOOGLE_SHOPPING'
33
				| 'FACEBOOK_MESSENGER'
34
				| 'LINKEDIN_CONTENT'
35
				| 'LINKEDIN_TEXT'
36
				| 'LINKEDIN_INMAIL'
37
				| 'LINKEDIN_DYNAMIC'
38
				| 'FACEBOOK_STORIES'
39
				| 'FACEBOOK_INSTANT_ARTICLES'
40
				| 'FACEBOOK_RIGHT_HAND_COLUMN'
41
				| 'FACEBOOK_MARKETPLACE'
42
				| 'INSTAGRAM_STORIES'
43
				| 'FACEBOOK_MESSENGER_STORIES'
44
				| 'FACEBOOK_SEARCH'
45
				| 'FACEBOOK_INSTREAM_VIDEO'
46
				| 'FACEBOOK_REELS'
47
				| 'INSTAGRAM_EXPLORE_HOME'
48
				| 'INSTAGRAM_PROFILE_FEED'
49
				| 'INSTAGRAM_PROFILE_REELS'
50
				| 'LINKEDIN_AUDIENCE_NETWORK'
51
				| 'TWITTER_ALL'
52
				| 'TWITTER_PUBLISHER_NETWORK'
53
				| 'TWITTER_SEARCH'
54
				| 'TWITTER_TIMELINE'
55
				| 'TWITTER_PROFILE'
56
				| 'FACEBOOK_UNKNOWN'
57
				| 'FACEBOOK_VIDEO_FEED'
58
				| 'INSTAGRAM_REELS'
59
				| 'INSTAGRAM_SHOP'
60
				| 'INSTAGRAM_EXPLORE'
61
				| 'TIKTOK_FEED'
62
				| 'META_AUTOMATIC'
63
			selected?: false | true
64
			totalCost?: number
65
			bid?: number
66
			maxBid?: number
67
			costType?: 'CPC' | 'CPM'
68
			bidType?: 'AUTOMATIC' | 'MANUAL'
69
			linkedInBiddingOptimization?:
70
				| 'MAXIMIZE_CLICKS'
71
				| 'MAXIMIZE_IMPRESSIONS'
72
				| 'MAXIMIZE_CONVERSIONS'
73
				| 'MAXIMIZE_LEADS'
74
			linkedInDailyBudget?: number
75
			facebookBudgetOptimization?: 'CAMPAIGN_BUDGET_OPTIMIZATION' | 'ADSET_BUDGET_OPTIMIZATION'
76
			facebookTrafficOptimization?: 'LINK_CLICKS' | 'LANDING_PAGE_VIEWS'
77
			twitterBudgetOptimization?: 'CAMPAIGN_BUDGET_OPTIMIZATION' | 'AD_GROUP_BUDGET_OPTIMIZATION'
78
			tikTokBudgetOptimization?: 'CAMPAIGN_BUDGET_OPTIMIZATION' | 'AD_GROUP_BUDGET_OPTIMIZATION'
79
			targetBudgets?: {
80
				targetId?: string
81
				budget?: number
82
				linkedInDailyBudget?: number
83
				metaBudgetSplit?: {
84
					facebookBudget?: number
85
					instagramBudget?: number
86
					storyBudget?: number
87
					reelsBudget?: number
88
				}
89
			}[]
90
		}[]
91
	}
92
) {
93
	const url = new URL(`https://app.adhook.io/v1/promotions/${id}/budgetSettings`)
94

95
	const response = await fetch(url, {
96
		method: 'PUT',
97
		headers: {
98
			Authorization: `Bearer ${auth.token}`,
99
			'Content-Type': 'application/json'
100
		},
101
		body: JSON.stringify(body)
102
	})
103

104
	if (!response.ok) {
105
		const text = await response.text()
106
		throw new Error(`${response.status} ${text}`)
107
	}
108

109
	return await response.json()
110
}
111