0

Send Document

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
		message?: string
11
		subject?: string
12
		silent?: false | true
13
		sender?: {}
14
		forwarding_settings?: {
15
			forwarding_allowed?: false | true
16
			forwarding_with_reassigning_allowed?: false | true
17
		}
18
		selected_approvers?: {
19
			steps?: {
20
				id: string
21
				group: {
22
					id: string
23
					type: string
24
					assignees: { user?: string; is_selected?: false | true }[]
25
				}
26
			}[]
27
		}
28
	}
29
) {
30
	const url = new URL(`https://api.pandadoc.com/public/v1/documents/${id}/send`)
31

32
	const response = await fetch(url, {
33
		method: 'POST',
34
		headers: {
35
			'Content-Type': 'application/json',
36
			Authorization: `API-Key ${auth.apiKey}`
37
		},
38
		body: JSON.stringify(body)
39
	})
40

41
	if (!response.ok) {
42
		const text = await response.text()
43
		throw new Error(`${response.status} ${text}`)
44
	}
45

46
	return await response.json()
47
}
48