0

Transfer all documents ownership

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
	body: { from_membership_id?: string; to_membership_id?: string }
9
) {
10
	const url = new URL(`https://api.pandadoc.com/public/v1/documents/ownership`)
11

12
	const response = await fetch(url, {
13
		method: 'PATCH',
14
		headers: {
15
			'Content-Type': 'application/json',
16
			Authorization: `API-Key ${auth.apiKey}`
17
		},
18
		body: JSON.stringify(body)
19
	})
20

21
	if (!response.ok) {
22
		const text = await response.text()
23
		throw new Error(`${response.status} ${text}`)
24
	}
25

26
	return await response.text()
27
}
28