0

Create contact

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

23
	const response = await fetch(url, {
24
		method: 'POST',
25
		headers: {
26
			'Content-Type': 'application/json',
27
			Authorization: `API-Key ${auth.apiKey}`
28
		},
29
		body: JSON.stringify(body)
30
	})
31

32
	if (!response.ok) {
33
		const text = await response.text()
34
		throw new Error(`${response.status} ${text}`)
35
	}
36

37
	return await response.json()
38
}
39