0

Create dev resources

by
Published Apr 8, 2025

Bulk create dev resources across multiple files.

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 dev resources
7
 * Bulk create dev resources across multiple files.
8
 */
9
export async function main(
10
  auth: Figma,
11
  body: {
12
    dev_resources: {
13
      name: string;
14
      url: string;
15
      file_key: string;
16
      node_id: string;
17
    }[];
18
  },
19
) {
20
  const url = new URL(`https://api.figma.com/v1/dev_resources`);
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      "Content-Type": "application/json",
26
      Authorization: "Bearer " + auth.token,
27
    },
28
    body: JSON.stringify(body),
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