1 | |
2 | type Pandadoc = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Pandadoc, |
8 | body: { |
9 | name: string |
10 | url: string |
11 | payload?: 'metadata' | 'fields' | 'products' | 'tokens' | 'pricing'[] |
12 | triggers: |
13 | | 'recipient_completed' |
14 | | 'document_updated' |
15 | | 'document_deleted' |
16 | | 'document_state_changed' |
17 | | 'document_creation_failed' |
18 | | 'quote_updated'[] |
19 | } |
20 | ) { |
21 | const url = new URL(`https://api.pandadoc.com/public/v1/webhook-subscriptions`) |
22 |
|
23 | const response = await fetch(url, { |
24 | method: 'POST', |
25 | headers: { |
26 | 'Content-Type': 'application/json', |
27 | Authorization: `API-Key ${auth.apiKey}` |
28 | }, |
29 | body: JSON.stringify(body) |
30 | }) |
31 |
|
32 | if (!response.ok) { |
33 | const text = await response.text() |
34 | throw new Error(`${response.status} ${text}`) |
35 | } |
36 |
|
37 | return await response.json() |
38 | } |
39 |
|