0

Convert a conversation to a ticket

by
Published Dec 20, 2024

You can convert a conversation to a 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
 * Convert a conversation to a ticket
8
 * You can convert a conversation to a ticket.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	id: string,
13
	body: { ticket_type_id: string; attributes?: {} }
14
) {
15
	const url = new URL(`https://api.intercom.io/conversations/${id}/convert`)
16

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