0

Update an existing attribute for a ticket type

by
Published Dec 20, 2024

You can update an existing attribute for a ticket type.

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 an existing attribute for a ticket type
8
 * You can update an existing attribute for a ticket type.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	ticket_type_id: string,
13
	id: string,
14
	body: {
15
		name?: string
16
		description?: string
17
		required_to_create?: false | true
18
		required_to_create_for_contacts?: false | true
19
		visible_on_create?: false | true
20
		visible_to_contacts?: false | true
21
		multiline?: false | true
22
		list_items?: string
23
		allow_multiple_values?: false | true
24
		archived?: false | true
25
	}
26
) {
27
	const url = new URL(`https://api.intercom.io/ticket_types/${ticket_type_id}/attributes/${id}`)
28

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