0

Create a ticket

by
Published Dec 20, 2024

You can create a new ticket.

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
8
 * You can create a new ticket.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	body: {
13
		ticket_type_id: string
14
		contacts: { id: string } | { external_id: string } | { email: string }[]
15
		company_id?: string
16
		created_at?: number
17
		ticket_attributes?: {}
18
	}
19
) {
20
	const url = new URL(`https://api.intercom.io/tickets`)
21

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