1 | |
2 | type Bitly = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create Webhook |
7 | * Creates a webhook. |
8 | */ |
9 | export async function main( |
10 | auth: Bitly, |
11 | body: { |
12 | is_active?: false | true; |
13 | organization_guid: string; |
14 | group_guid?: string; |
15 | name: string; |
16 | event: string; |
17 | url: string; |
18 | oauth_url?: string; |
19 | client_id?: string; |
20 | client_secret?: string; |
21 | fetch_tags?: false | true; |
22 | }, |
23 | ) { |
24 | const url = new URL(`https://api-ssl.bitly.com/v4/webhooks`); |
25 |
|
26 | const response = await fetch(url, { |
27 | method: "POST", |
28 | headers: { |
29 | "Content-Type": "application/json", |
30 | Authorization: "Bearer " + auth.token, |
31 | }, |
32 | body: JSON.stringify(body), |
33 | }); |
34 | if (!response.ok) { |
35 | const text = await response.text(); |
36 | throw new Error(`${response.status} ${text}`); |
37 | } |
38 | return await response.json(); |
39 | } |
40 |
|