1 |
|
2 | type Adhook = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Adhook, |
8 | facebookAccountId: string | undefined, |
9 | instagramAccountId: string | undefined, |
10 | adhookToken: string, |
11 | Origin: string |
12 | ) { |
13 | const url = new URL(`https://app.adhook.io/v1/promotions/facebook/catalogs`) |
14 |
|
15 | for (const [k, v] of [ |
16 | ['facebookAccountId', facebookAccountId], |
17 | ['instagramAccountId', instagramAccountId] |
18 | ]) { |
19 | if (v !== undefined && v !== '' && k !== undefined) { |
20 | url.searchParams.append(k, v) |
21 | } |
22 | } |
23 |
|
24 | const response = await fetch(url, { |
25 | method: 'GET', |
26 | headers: { |
27 | adhookToken: adhookToken, |
28 | Authorization: `Bearer ${auth.token}`, |
29 | Origin: Origin |
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 |
|