1 | |
2 | type Pandadoc = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Pandadoc, |
8 | id: string, |
9 | body: { |
10 | email?: string |
11 | first_name?: string |
12 | last_name?: string |
13 | company?: string |
14 | job_title?: string |
15 | phone?: string |
16 | state?: string |
17 | street_address?: string |
18 | city?: string |
19 | postal_code?: string |
20 | } |
21 | ) { |
22 | const url = new URL(`https://api.pandadoc.com/public/v1/contacts/${id}`) |
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.json() |
39 | } |
40 |
|