0
Create Comment
One script reply has been approved by the moderators Verified

Use this endpoint to create a new comment on a post.

Created by hugo697 2 days ago Viewed 140 times
0
Submitted by hugo697 Bun
Verified 2 days ago
1
//native
2
type Beamer = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	resource: Beamer,
8
	postId: string,
9
	commentData: {
10
		text?: string
11
		userId?: string
12
		userEmail?: string
13
		userFirstname?: string
14
		userLastname?: string
15
	}
16
) {
17
	const endpoint = `https://api.getbeamer.com/v0/posts/${postId}/comments`
18

19
	const response = await fetch(endpoint, {
20
		method: 'POST',
21
		headers: {
22
			Accept: 'application/json',
23
			'Beamer-Api-Key': resource.apiKey,
24
			'Content-Type': 'application/json'
25
		},
26
		body: JSON.stringify(commentData)
27
	})
28

29
	if (!response.ok) {
30
		const text = await response.text()
31
		throw new Error(`${response.status} ${text}`)
32
	}
33

34
	const data = await response.json()
35

36
	return data
37
}
38