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

Use this endpoint to create a new reaction 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
	reactionData: {
10
		reaction?: 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}/reactions`
18

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

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

33
	const data = await response.json()
34
	return data
35
}
36