0

List reactions

by
Published Oct 17, 2025

List all reactions for a comment.

Script phrase Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Phrase = {
3
	token: string
4
	baseUrl: string
5
}
6
/**
7
 * List reactions
8
 * List all reactions for a comment.
9
 */
10
export async function main(
11
	auth: Phrase,
12
	project_id: string,
13
	key_id: string,
14
	comment_id: string,
15
	page: string | undefined,
16
	per_page: string | undefined,
17
	branch: string | undefined
18
) {
19
	const url = new URL(
20
		`${auth.baseUrl}/projects/${project_id}/keys/${key_id}/comments/${comment_id}/reactions`
21
	)
22
	for (const [k, v] of [
23
		['page', page],
24
		['per_page', per_page],
25
		['branch', branch]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'ApiToken ' + auth.token
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44