1 | |
2 | type Pandadoc = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Pandadoc, |
8 | id: string, |
9 | body: { |
10 | status: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
11 | note?: string |
12 | notify_recipients?: false | true |
13 | } |
14 | ) { |
15 | const url = new URL(`https://api.pandadoc.com/public/v1/documents/${id}/status`) |
16 |
|
17 | const formData = new FormData() |
18 | for (const [k, v] of Object.entries(body)) { |
19 | if (v !== undefined && v !== '' && k !== undefined) { |
20 | formData.append(k, String(v)) |
21 | } |
22 | } |
23 |
|
24 | const response = await fetch(url, { |
25 | method: 'PATCH', |
26 | headers: { |
27 | 'Content-Type': 'application/json', |
28 | Authorization: `API-Key ${auth.apiKey}` |
29 | }, |
30 | body: JSON.stringify(body) |
31 | }) |
32 |
|
33 | if (!response.ok) { |
34 | const text = await response.text() |
35 | throw new Error(`${response.status} ${text}`) |
36 | } |
37 |
|
38 | return await response.text() |
39 | } |
40 |
|