1 | |
2 | type Figma = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a webhook |
7 | * Update a webhook by ID. |
8 | */ |
9 | export async function main( |
10 | auth: Figma, |
11 | webhook_id: string, |
12 | body: { |
13 | event_type: |
14 | | "PING" |
15 | | "FILE_UPDATE" |
16 | | "FILE_VERSION_UPDATE" |
17 | | "FILE_DELETE" |
18 | | "LIBRARY_PUBLISH" |
19 | | "FILE_COMMENT"; |
20 | endpoint: string; |
21 | passcode: string; |
22 | status?: "ACTIVE" | "PAUSED"; |
23 | description?: string; |
24 | }, |
25 | ) { |
26 | const url = new URL(`https://api.figma.com/v2/webhooks/${webhook_id}`); |
27 |
|
28 | const response = await fetch(url, { |
29 | method: "PUT", |
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 |
|