Create communication plan item

Creates 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
	Origin: 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`)
26

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

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

42
	return await response.json()
43
}
44