0
Get schools
One script reply has been approved by the moderators Verified
Created by hugo697 200 days ago Viewed 13470 times
0
Submitted by hugo697 Bun
Verified 200 days ago
1
//native
2
type Adhook = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Adhook,
8
	q: string | undefined,
9
	lang: string | undefined,
10
	accountId: string | undefined,
11
	adhookToken: string
12
) {
13
	const url = new URL(`https://app.adhook.io/v1/promotions/linkedin/targeting/schools`)
14

15
	for (const [k, v] of [
16
		['q', q],
17
		['lang', lang],
18
		['accountId', accountId]
19
	]) {
20
		if (v !== undefined && v !== '' && k !== undefined) {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24
	const response = await fetch(url, {
25
		method: 'GET',
26
		headers: {
27
			adhookToken: adhookToken,
28
			Authorization: `Bearer ${auth.token}`
29
		},
30
		body: undefined
31
	})
32

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

38
	return await response.json()
39
}
40