0

Delete a reaction

by
Published Apr 8, 2025

Deletes a specific comment reaction. Only the person who made the reaction is allowed to delete it.

Script figma Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Figma = {
3
  token: string;
4
};
5
/**
6
 * Delete a reaction
7
 * Deletes a specific comment reaction. Only the person who made the reaction is allowed to delete it.
8
 */
9
export async function main(
10
  auth: Figma,
11
  file_key: string,
12
  comment_id: string,
13
  emoji: string | undefined,
14
) {
15
  const url = new URL(
16
    `https://api.figma.com/v1/files/${file_key}/comments/${comment_id}/reactions`,
17
  );
18
  for (const [k, v] of [["emoji", emoji]]) {
19
    if (v !== undefined && v !== "" && k !== undefined) {
20
      url.searchParams.append(k, v);
21
    }
22
  }
23
  const response = await fetch(url, {
24
    method: "DELETE",
25
    headers: {
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36