Get browseable write subtenants

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
	mode:
9
		| 'CAMPAIGN'
10
		| 'POST'
11
		| 'CAMPAIGN_GENERATION'
12
		| 'POST_GENERATION'
13
		| 'POST_TEMPLATE'
14
		| 'AD_TEMPLATE'
15
		| 'MANAGE'
16
		| 'REVIEW'
17
		| 'MODERATION'
18
		| 'DEFAULT'
19
		| undefined,
20
	q: string | undefined,
21
	skip: string | undefined,
22
	limit: string | undefined,
23
	adhookToken: string
24
) {
25
	const url = new URL(`https://app.adhook.io/v1/subtenants/write/browse`)
26

27
	for (const [k, v] of [
28
		['mode', mode],
29
		['q', q],
30
		['skip', skip],
31
		['limit', limit]
32
	]) {
33
		if (v !== undefined && v !== '' && k !== undefined) {
34
			url.searchParams.append(k, v)
35
		}
36
	}
37

38
	const response = await fetch(url, {
39
		method: 'GET',
40
		headers: {
41
			adhookToken: adhookToken,
42
			Authorization: `Bearer ${auth.token}`
43
		},
44
		body: undefined
45
	})
46

47
	if (!response.ok) {
48
		const text = await response.text()
49
		throw new Error(`${response.status} ${text}`)
50
	}
51

52
	return await response.json()
53
}
54