1 | |
2 | type Attio = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a webhook |
7 | * Update a webhook and associated subscriptions. |
8 |
|
9 | Required scopes: `webhook:read-write`. |
10 | */ |
11 | export async function main( |
12 | auth: Attio, |
13 | webhook_id: string, |
14 | body: { |
15 | data: { |
16 | target_url?: string; |
17 | subscriptions?: { |
18 | event_type: |
19 | | "comment.created" |
20 | | "comment.resolved" |
21 | | "comment.unresolved" |
22 | | "comment.deleted" |
23 | | "list.created" |
24 | | "list.updated" |
25 | | "list.deleted" |
26 | | "list-attribute.created" |
27 | | "list-attribute.updated" |
28 | | "list-entry.created" |
29 | | "list-entry.updated" |
30 | | "list-entry.deleted" |
31 | | "object-attribute.created" |
32 | | "object-attribute.updated" |
33 | | "note.created" |
34 | | "note.updated" |
35 | | "note.deleted" |
36 | | "record.created" |
37 | | "record.merged" |
38 | | "record.updated" |
39 | | "record.deleted" |
40 | | "task.created" |
41 | | "task.updated" |
42 | | "task.deleted" |
43 | | "workspace-member.created"; |
44 | filter: |
45 | | { |
46 | $or: |
47 | | { field: string; operator: "equals"; value: string } |
48 | | { field: string; operator: "not_equals"; value: string }[]; |
49 | } |
50 | | { |
51 | $and: |
52 | | { field: string; operator: "equals"; value: string } |
53 | | { field: string; operator: "not_equals"; value: string }[]; |
54 | }; |
55 | }[]; |
56 | }; |
57 | }, |
58 | ) { |
59 | const url = new URL(`https://api.attio.com/v2/webhooks/${webhook_id}`); |
60 |
|
61 | const response = await fetch(url, { |
62 | method: "PATCH", |
63 | headers: { |
64 | "Content-Type": "application/json", |
65 | Authorization: "Bearer " + auth.token, |
66 | }, |
67 | body: JSON.stringify(body), |
68 | }); |
69 | if (!response.ok) { |
70 | const text = await response.text(); |
71 | throw new Error(`${response.status} ${text}`); |
72 | } |
73 | return await response.json(); |
74 | } |
75 |
|