1 |
|
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 |
|