0

Create or update a tag, Tag or untag companies, Tag contacts

by
Published Dec 20, 2024

You can use this endpoint to perform the following operations: **1.

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 or update a tag, Tag or untag companies, Tag contacts
8
 * You can use this endpoint to perform the following operations:
9

10
  **1.
11
 */
12
export async function main(
13
	auth: Intercom,
14
	body:
15
		| { name: string; id?: string }
16
		| { name: string; companies: { id?: string; company_id?: string }[] }
17
		| {
18
				name: string
19
				companies: { id?: string; company_id?: string; untag?: false | true }[]
20
		  }
21
		| { name: string; users: { id?: string }[] }
22
) {
23
	const url = new URL(`https://api.intercom.io/tags`)
24

25
	const response = await fetch(url, {
26
		method: 'POST',
27
		headers: {
28
			'Intercom-Version': auth.apiVersion,
29
			'Content-Type': 'application/json',
30
			Authorization: 'Bearer ' + auth.token
31
		},
32
		body: JSON.stringify(body)
33
	})
34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38
	return await response.json()
39
}
40