0

Update a collection

by
Published Dec 20, 2024

You can update the details of a single collection by making a PUT request to `https://api.intercom.io/collections/`.

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 collection
8
 * You can update the details of a single collection by making a PUT request to `https://api.intercom.io/collections/`.
9
 */
10
export async function main(
11
	auth: Intercom,
12
	id: string,
13
	body: {
14
		name?: string
15
		description?: string
16
		translated_content?: {
17
			type?: 'group_translated_content'
18
			ar?: { type?: 'group_content'; name?: string; description?: string }
19
			bg?: { type?: 'group_content'; name?: string; description?: string }
20
			bs?: { type?: 'group_content'; name?: string; description?: string }
21
			ca?: { type?: 'group_content'; name?: string; description?: string }
22
			cs?: { type?: 'group_content'; name?: string; description?: string }
23
			da?: { type?: 'group_content'; name?: string; description?: string }
24
			de?: { type?: 'group_content'; name?: string; description?: string }
25
			el?: { type?: 'group_content'; name?: string; description?: string }
26
			en?: { type?: 'group_content'; name?: string; description?: string }
27
			es?: { type?: 'group_content'; name?: string; description?: string }
28
			et?: { type?: 'group_content'; name?: string; description?: string }
29
			fi?: { type?: 'group_content'; name?: string; description?: string }
30
			fr?: { type?: 'group_content'; name?: string; description?: string }
31
			he?: { type?: 'group_content'; name?: string; description?: string }
32
			hr?: { type?: 'group_content'; name?: string; description?: string }
33
			hu?: { type?: 'group_content'; name?: string; description?: string }
34
			id?: { type?: 'group_content'; name?: string; description?: string }
35
			it?: { type?: 'group_content'; name?: string; description?: string }
36
			ja?: { type?: 'group_content'; name?: string; description?: string }
37
			ko?: { type?: 'group_content'; name?: string; description?: string }
38
			lt?: { type?: 'group_content'; name?: string; description?: string }
39
			lv?: { type?: 'group_content'; name?: string; description?: string }
40
			mn?: { type?: 'group_content'; name?: string; description?: string }
41
			nb?: { type?: 'group_content'; name?: string; description?: string }
42
			nl?: { type?: 'group_content'; name?: string; description?: string }
43
			pl?: { type?: 'group_content'; name?: string; description?: string }
44
			pt?: { type?: 'group_content'; name?: string; description?: string }
45
			ro?: { type?: 'group_content'; name?: string; description?: string }
46
			ru?: { type?: 'group_content'; name?: string; description?: string }
47
			sl?: { type?: 'group_content'; name?: string; description?: string }
48
			sr?: { type?: 'group_content'; name?: string; description?: string }
49
			sv?: { type?: 'group_content'; name?: string; description?: string }
50
			tr?: { type?: 'group_content'; name?: string; description?: string }
51
			vi?: { type?: 'group_content'; name?: string; description?: string }
52
			'pt-BR'?: { type?: 'group_content'; name?: string; description?: string }
53
			'zh-CN'?: { type?: 'group_content'; name?: string; description?: string }
54
			'zh-TW'?: { type?: 'group_content'; name?: string; description?: string }
55
		}
56
		parent_id?: string
57
	}
58
) {
59
	const url = new URL(`https://api.intercom.io/help_center/collections/${id}`)
60

61
	const response = await fetch(url, {
62
		method: 'PUT',
63
		headers: {
64
			'Intercom-Version': auth.apiVersion,
65
			'Content-Type': 'application/json',
66
			Authorization: 'Bearer ' + auth.token
67
		},
68
		body: JSON.stringify(body)
69
	})
70
	if (!response.ok) {
71
		const text = await response.text()
72
		throw new Error(`${response.status} ${text}`)
73
	}
74
	return await response.json()
75
}
76