0

Create contact

by
Published Dec 20, 2024

You can create a new contact (ie. user or lead).

Script intercom Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Intercom = {
3
	apiVersion: string
4
	token: string
5
}
6
/**
7
 * Create contact
8
 * You can create a new contact (ie. user or lead).
9
 */
10
export async function main(auth: Intercom, body: {} | {} | {}) {
11
	const url = new URL(`https://api.intercom.io/contacts`)
12

13
	const response = await fetch(url, {
14
		method: 'POST',
15
		headers: {
16
			'Intercom-Version': auth.apiVersion,
17
			'Content-Type': 'application/json',
18
			Authorization: 'Bearer ' + auth.token
19
		},
20
		body: JSON.stringify(body)
21
	})
22
	if (!response.ok) {
23
		const text = await response.text()
24
		throw new Error(`${response.status} ${text}`)
25
	}
26
	return await response.json()
27
}
28