0

Create a new attribute for a ticket type

by
Published Dec 20, 2024

You can create a new 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
 * Create a new attribute for a ticket type
8
 * You can create a new attribute for a ticket type.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	ticket_type_id: string,
13
	body: {
14
		name: string
15
		description: string
16
		data_type: 'string' | 'boolean' | 'list' | 'integer' | 'decimal' | 'datetime' | 'files'
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
	}
25
) {
26
	const url = new URL(`https://api.intercom.io/ticket_types/${ticket_type_id}/attributes`)
27

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