0

Delete a contact

by
Published Dec 20, 2024

You can delete a single contact.

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
 * Delete a contact
8
 * You can delete a single contact.
9
 */
10
export async function main(auth: Intercom, id: string) {
11
	const url = new URL(`https://api.intercom.io/contacts/${id}`)
12

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