0

Create a news item

by
Published Dec 20, 2024

You can create a news item

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 news item
8
 * You can create a news item
9
 */
10
export async function main(
11
	auth: Intercom,
12
	body: {
13
		title: string
14
		body?: string
15
		sender_id: number
16
		state?: 'draft' | 'live'
17
		deliver_silently?: false | true
18
		labels?: string[]
19
		reactions?: string[]
20
		newsfeed_assignments?: { newsfeed_id?: number; published_at?: number }[]
21
	}
22
) {
23
	const url = new URL(`https://api.intercom.io/news/news_items`)
24

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