1 | |
2 | type Netlify = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update hook |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Netlify, |
11 | hook_id: string, |
12 | body: { |
13 | id?: string; |
14 | site_id?: string; |
15 | type?: string; |
16 | event?: string; |
17 | data?: {}; |
18 | created_at?: string; |
19 | updated_at?: string; |
20 | disabled?: false | true; |
21 | }, |
22 | ) { |
23 | const url = new URL(`https://api.netlify.com/api/v1/hooks/${hook_id}`); |
24 |
|
25 | const response = await fetch(url, { |
26 | method: "PUT", |
27 | headers: { |
28 | "Content-Type": "application/json", |
29 | Authorization: "Bearer " + auth.token, |
30 | }, |
31 | body: JSON.stringify(body), |
32 | }); |
33 | if (!response.ok) { |
34 | const text = await response.text(); |
35 | throw new Error(`${response.status} ${text}`); |
36 | } |
37 | return await response.json(); |
38 | } |
39 |
|