0
Get linked in pages
One script reply has been approved by the moderators Verified
Created by hugo697 14 days ago Viewed 1202 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(auth: Adhook, accountId: string | undefined, adhookToken: string) {
7
	const url = new URL(`https://app.adhook.io/v1/promotions/linkedin/pages`)
8

9
	for (const [k, v] of [['accountId', accountId]]) {
10
		if (v !== undefined && v !== '' && k !== undefined) {
11
			url.searchParams.append(k, v)
12
		}
13
	}
14

15
	const response = await fetch(url, {
16
		method: 'GET',
17
		headers: {
18
			adhookToken: adhookToken,
19
			Authorization: `Bearer ${auth.token}`
20
		},
21
		body: undefined
22
	})
23

24
	if (!response.ok) {
25
		const text = await response.text()
26
		throw new Error(`${response.status} ${text}`)
27
	}
28

29
	return await response.json()
30
}
31