0
Get degrees
One script reply has been approved by the moderators Verified
Created by hugo697 14 days ago Viewed 1195 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
	q: string | undefined,
9
	lang: string | undefined,
10
	adhookToken: string
11
) {
12
	const url = new URL(`https://app.adhook.io/v1/promotions/linkedin/targeting/degrees`)
13

14
	for (const [k, v] of [
15
		['q', q],
16
		['lang', lang]
17
	]) {
18
		if (v !== undefined && v !== '' && k !== undefined) {
19
			url.searchParams.append(k, v)
20
		}
21
	}
22

23
	const response = await fetch(url, {
24
		method: 'GET',
25
		headers: {
26
			adhookToken: adhookToken,
27
			Authorization: `Bearer ${auth.token}`
28
		},
29
		body: undefined
30
	})
31

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

37
	return await response.json()
38
}
39