0

Update Document only in the draft status

by
Published Nov 5, 2024
Script pandadoc Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Pandadoc = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Pandadoc,
8
	id: string,
9
	body: {
10
		name?: string
11
		recipients?: {
12
			id?: string
13
			email?: string
14
			first_name?: string
15
			last_name?: string
16
		}[]
17
		fields?: {}
18
		tokens?: { name: string; value: string }[]
19
		metadata?: {}
20
		pricing_tables?: {
21
			name: string
22
			data_merge?: false | true
23
			options?: {}
24
			sections?: {
25
				title: string
26
				default?: false | true
27
				multichoice_enabled?: false | true
28
				rows?: {
29
					options?: {
30
						qty_editable?: false | true
31
						optional_selected?: false | true
32
						optional?: false | true
33
					}
34
					data?: {}
35
					custom_fields?: {}
36
				}[]
37
			}[]
38
		}[]
39
	}
40
) {
41
	const url = new URL(`https://api.pandadoc.com/public/v1/documents/${id}`)
42

43
	const response = await fetch(url, {
44
		method: 'PATCH',
45
		headers: {
46
			'Content-Type': 'application/json',
47
			Authorization: `API-Key ${auth.apiKey}`
48
		},
49
		body: JSON.stringify(body)
50
	})
51

52
	if (!response.ok) {
53
		const text = await response.text()
54
		throw new Error(`${response.status} ${text}`)
55
	}
56

57
	return await response.text()
58
}
59