0

Add tag to a conversation

by
Published Dec 20, 2024

You can tag a specific conversation. This will return a tag object for the tag that was added to the conversation.

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

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