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

25
	const response = await fetch(url, {
26
		method: 'GET',
27
		headers: {
28
			adhookToken: adhookToken,
29
			Authorization: `Bearer ${auth.token}`
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