0

Add a reaction to a comment

by
Published Apr 8, 2025

Posts a new comment reaction on a file comment.

Script figma Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Figma = {
3
  token: string;
4
};
5
/**
6
 * Add a reaction to a comment
7
 * Posts a new comment reaction on a file comment.
8
 */
9
export async function main(
10
  auth: Figma,
11
  file_key: string,
12
  comment_id: string,
13
  body: { emoji: string },
14
) {
15
  const url = new URL(
16
    `https://api.figma.com/v1/files/${file_key}/comments/${comment_id}/reactions`,
17
  );
18

19
  const response = await fetch(url, {
20
    method: "POST",
21
    headers: {
22
      "Content-Type": "application/json",
23
      Authorization: "Bearer " + auth.token,
24
    },
25
    body: JSON.stringify(body),
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33