0

Reassign Document Recipient

by
Published Nov 5, 2024

Replace document recipient with another contact

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: { id: string; kind: 'contact' | 'contact_group' }
11
) {
12
	const url = new URL(
13
		`https://api.pandadoc.com/public/v1/documents/${id}/recipients/${recipient_id}/reassign`
14
	)
15

16
	const response = await fetch(url, {
17
		method: 'POST',
18
		headers: {
19
			'Content-Type': 'application/json',
20
			Authorization: `API-Key ${auth.apiKey}`
21
		},
22
		body: JSON.stringify(body)
23
	})
24

25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29

30
	return await response.json()
31
}
32