0

Create a webhook

by
Published Apr 8, 2025

Create a new webhook which will call the specified endpoint when the event triggers. By default, this webhook will automatically send a PING event to the endpoint when it is created. If this behavior is not desired, you can create the webhook and set the status to PAUSED and reactivate it later.

Script figma Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Figma = {
3
  token: string;
4
};
5
/**
6
 * Create a webhook
7
 * Create a new webhook which will call the specified endpoint when the event triggers. By default, this webhook will automatically send a PING event to the endpoint when it is created. If this behavior is not desired, you can create the webhook and set the status to PAUSED and reactivate it later.
8
 */
9
export async function main(
10
  auth: Figma,
11
  body: {
12
    event_type:
13
      | "PING"
14
      | "FILE_UPDATE"
15
      | "FILE_VERSION_UPDATE"
16
      | "FILE_DELETE"
17
      | "LIBRARY_PUBLISH"
18
      | "FILE_COMMENT";
19
    team_id: string;
20
    endpoint: string;
21
    passcode: string;
22
    status?: "ACTIVE" | "PAUSED";
23
    description?: string;
24
  },
25
) {
26
  const url = new URL(`https://api.figma.com/v2/webhooks`);
27

28
  const response = await fetch(url, {
29
    method: "POST",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42