0

Add tag to a contact

by
Published Dec 20, 2024

You can tag a specific contact. This will return a tag object for the tag that was added to the 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
 * Add tag to a contact
8
 * You can tag a specific contact. This will return a tag object for the tag that was added to the contact.
9
 */
10
export async function main(auth: Intercom, contact_id: string, body: { id: string }) {
11
	const url = new URL(`https://api.intercom.io/contacts/${contact_id}/tags`)
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