figma

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Read Figma via
curl + jq
. The user's OAuth bearer token is in
$FIGMA_TOKEN
; every call needs
Authorization: Bearer $FIGMA_TOKEN
. Base URL:
https://api.figma.com/v1
.
Failures are
{"status":<code>,"err":"..."}
— show
err
verbatim.
403
means the token lacks the scope or the file isn't shared with the user.
404
= bad file key.
The file key is the
figma.com/file/<KEY>/...
or
figma.com/design/<KEY>/...
segment of a pasted URL. A node id is in
?node-id=1-23
(Figma shows
1:23
; the API also accepts
1:23
).
bash
F="https://api.figma.com/v1"; AUTH="Authorization: Bearer $FIGMA_TOKEN"
通过
curl + jq
读取 Figma 内容。用户的OAuth bearer token存储在
$FIGMA_TOKEN
中;每次调用都需要携带
Authorization: Bearer $FIGMA_TOKEN
请求头。基础URL:
https://api.figma.com/v1
失败响应格式为
{"status":<code>,"err":"..."}
—— 直接显示
err
字段内容。
403
表示令牌缺少权限范围,或文件未与用户共享。
404
表示文件密钥无效。
文件密钥是粘贴的URL中
figma.com/file/<KEY>/...
figma.com/design/<KEY>/...
部分的内容。节点ID在URL的
?node-id=1-23
参数中(Figma界面显示为
1:23
;API也接受
1:23
格式)。
bash
F="https://api.figma.com/v1"; AUTH="Authorization: Bearer $FIGMA_TOKEN"

Who am I (account card)

查看当前账号信息

curl -sS -H "$AUTH" "$F/me" | jq '{handle, email}'
curl -sS -H "$AUTH" "$F/me" | jq '{handle, email}'

File document tree (name + top-level frames). Big files: prefer /nodes below.

文件文档树(名称 + 顶层框架)。大文件建议使用下方的/nodes接口。

curl -sS -H "$AUTH" "$F/files/FILE_KEY?depth=2"
| jq '{name, pages: [.document.children[] | {name, frames: [.children[]?.name]}]}'
undefined
curl -sS -H "$AUTH" "$F/files/FILE_KEY?depth=2"
| jq '{name, pages: [.document.children[] | {name, frames: [.children[]?.name]}]}'
undefined

Read specific nodes & render images

读取特定节点并渲染图像

bash
KEY="FILE_KEY"
bash
KEY="FILE_KEY"

Just the nodes you care about (faster than the whole file)

仅读取你关注的节点(比读取整个文件更快)

curl -sS -H "$AUTH" "$F/files/$KEY/nodes?ids=1:23,1:45"
| jq '.nodes | to_entries[] | {id: .key, name: .value.document.name, type: .value.document.type}'
curl -sS -H "$AUTH" "$F/files/$KEY/nodes?ids=1:23,1:45"
| jq '.nodes | to_entries[] | {id: .key, name: .value.document.name, type: .value.document.type}'

Render nodes to images — returns temporary CDN URLs (this is the "see it" tool)

将节点渲染为图像 —— 返回临时CDN链接(这是“可视化”工具)

curl -sS -H "$AUTH" "$F/images/$KEY?ids=1:23&format=png&scale=2"
| jq '.images' # { "1:23": "https://...png" }

For design-to-code, render the frame to PNG (to view) and read its node JSON
(layout/fills/typography) to extract exact colors, spacing and text.
curl -sS -H "$AUTH" "$F/images/$KEY?ids=1:23&format=png&scale=2"
| jq '.images' # { "1:23": "https://...png" }

对于设计转代码场景,可将框架渲染为PNG(用于查看)并读取其节点JSON(布局/填充/排版)以提取精确的颜色、间距和文本信息。

Comments & projects

评论与项目

bash
curl -sS -H "$AUTH" "$F/files/FILE_KEY/comments" \
  | jq '.comments[] | {user: .user.handle, at: .created_at, message}'
bash
curl -sS -H "$AUTH" "$F/files/FILE_KEY/comments" \
  | jq '.comments[] | {user: .user.handle, at: .created_at, message}'

Team projects → files (needs a team id from the Figma URL /team/<id>/...)

团队项目 → 文件(需要从Figma URL的/team/<id>/...部分获取团队ID)

curl -sS -H "$AUTH" "$F/teams/TEAM_ID/projects" | jq '.projects'
undefined
curl -sS -H "$AUTH" "$F/teams/TEAM_ID/projects" | jq '.projects'
undefined

Gotchas

注意事项

  • Node ids: Figma URLs use
    1-23
    (dash); the API wants
    1:23
    (colon). Convert.
  • /images
    URLs are temporary — download/use them promptly, don't store.
  • depth=
    limits tree traversal; omit it only for small files or you'll pull megabytes of node JSON.
  • 节点ID:Figma URL使用
    1-23
    (短横线);API要求使用
    1:23
    (冒号),需进行转换。
  • /images
    接口返回的链接是临时的 —— 请及时下载/使用,不要存储。
  • depth=
    参数限制树遍历深度;仅在处理小文件时省略该参数,否则会拉取数MB的节点JSON数据。