0

Create a ticket type

by
Published Dec 20, 2024

You can create a new ticket type. > 📘 Creating ticket types. > > Every ticket type will be created with two default attributes: _default_title_ and _default_description_. > For the `icon` propery, use an emoji from [Twemoji Cheatsheet](https://twemoji-cheatsheet.vercel.app/)

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 a ticket type
8
 * You can create a new ticket type.
9
> 📘 Creating ticket types.
10
>
11
> Every ticket type will be created with two default attributes: _default_title_ and _default_description_.
12
> For the `icon` propery, use an emoji from [Twemoji Cheatsheet](https://twemoji-cheatsheet.vercel.app/)
13

14
 */
15
export async function main(
16
	auth: Intercom,
17
	body: {
18
		name: string
19
		description?: string
20
		category?: 'Customer' | 'Back-office' | 'Tracker'
21
		icon?: string
22
		is_internal?: false | true
23
	}
24
) {
25
	const url = new URL(`https://api.intercom.io/ticket_types`)
26

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