Update communication plan item

Updates a topic

Script adhook Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 519 days ago
1
//native
2
type Adhook = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Adhook,
8
	id: string,
9
	body: {
10
		id?: string
11
		tenantId?: string
12
		subtenantId?: string
13
		name?: string
14
		description?: string
15
		start?: string
16
		end?: string
17
		color?: string
18
		parentAnnualPlanTopicId?: string
19
		createdAt?: string
20
		createdByUserId?: string
21
		createdByUserEmail?: string
22
		attachments?: { name?: string; url?: string; fileExtension?: string }[]
23
	}
24
) {
25
	const url = new URL(`https://app.adhook.io/v1/topics/${id}`)
26

27
	const response = await fetch(url, {
28
		method: 'PUT',
29
		headers: {
30
			Authorization: `Bearer ${auth.token}`,
31
			'Content-Type': 'application/json'
32
		},
33
		body: JSON.stringify(body)
34
	})
35

36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40

41
	return await response.json()
42
}
43