0

Merge a lead and a user

by
Published Dec 20, 2024

You can merge a contact with a `role` of `lead` into a contact with a `role` of `user`.

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
 * Merge a lead and a user
8
 * You can merge a contact with a `role` of `lead` into a contact with a `role` of `user`.
9
 */
10
export async function main(auth: Intercom, body: { from?: string; into?: string }) {
11
	const url = new URL(`https://api.intercom.io/contacts/merge`)
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