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