0

Edit Document Recipient

by
Published Nov 5, 2024

Edit document recipient's details

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
	recipient_id: string,
10
	body: {
11
		email?: string
12
		first_name?: string
13
		last_name?: string
14
		company?: string
15
		job_title?: string
16
		phone?: string
17
		state?: string
18
		street_address?: string
19
		city?: string
20
		postal_code?: string
21
	}
22
) {
23
	const url = new URL(
24
		`https://api.pandadoc.com/public/v1/documents/${id}/recipients/${recipient_id}`
25
	)
26

27
	const response = await fetch(url, {
28
		method: 'PATCH',
29
		headers: {
30
			'Content-Type': 'application/json',
31
			Authorization: `API-Key ${auth.apiKey}`
32
		},
33
		body: JSON.stringify(body)
34
	})
35

36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40

41
	return await response.text()
42
}
43