0

Update a ticket type

by
Published Dec 20, 2024

You can update a ticket type. > 📘 Updating a ticket type. > > 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
 * Update a ticket type
8
 * 
9
You can update a ticket type.
10

11
> 📘 Updating a ticket type.
12
>
13
> For the `icon` propery, use an emoji from [Twemoji Cheatsheet](https://twemoji-cheatsheet.vercel.app/)
14

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

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