0
Get targeting templates to manage
One script reply has been approved by the moderators Verified
Created by hugo697 14 days ago Viewed 1210 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
	filter: string | undefined,
9
	skip: string | undefined,
10
	status: 'ALL' | 'ACTIVE' | 'INACTIVE' | undefined,
11
	limit: string | undefined,
12
	Origin: string
13
) {
14
	const url = new URL(`https://app.adhook.io/v1/targetingTemplates/write`)
15
	for (const [k, v] of [
16
		['filter', filter],
17
		['skip', skip],
18
		['status', status],
19
		['limit', limit]
20
	]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25
	const response = await fetch(url, {
26
		method: 'GET',
27
		headers: {
28
			Authorization: `Bearer ${auth.token}`,
29
			Origin: Origin
30
		},
31
		body: undefined
32
	})
33

34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38

39
	return await response.json()
40
}
41