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