1 | |
2 | type Telnyx = { |
3 | apiKey: string |
4 | } |
5 | |
6 | * Update a document |
7 | * Update a document. |
8 | */ |
9 | export async function main( |
10 | auth: Telnyx, |
11 | id: string, |
12 | body: { |
13 | id?: string |
14 | record_type?: string |
15 | created_at?: string |
16 | updated_at?: string |
17 | } & { |
18 | record_type?: string |
19 | content_type?: string |
20 | size?: { unit?: string; amount?: number } |
21 | status?: 'pending' | 'verified' | 'denied' |
22 | sha256?: string |
23 | filename?: string |
24 | customer_reference?: string |
25 | } |
26 | ) { |
27 | const url = new URL(`https://api.telnyx.com/v2/documents/${id}`) |
28 |
|
29 | const response = await fetch(url, { |
30 | method: 'PATCH', |
31 | headers: { |
32 | 'Content-Type': 'application/json', |
33 | Authorization: 'Bearer ' + auth.apiKey |
34 | }, |
35 | body: JSON.stringify(body) |
36 | }) |
37 | if (!response.ok) { |
38 | const text = await response.text() |
39 | throw new Error(`${response.status} ${text}`) |
40 | } |
41 | return await response.json() |
42 | } |
43 |
|