figma
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRead Figma via . The user's OAuth bearer token is in
; every call needs . Base URL:
.
curl + jq$FIGMA_TOKENAuthorization: Bearer $FIGMA_TOKENhttps://api.figma.com/v1Failures are — show verbatim. means
the token lacks the scope or the file isn't shared with the user. = bad
file key.
{"status":<code>,"err":"..."}err403404The file key is the or
segment of a pasted URL. A node id is in (Figma shows ;
the API also accepts ).
figma.com/file/<KEY>/...figma.com/design/<KEY>/...?node-id=1-231:231:23bash
F="https://api.figma.com/v1"; AUTH="Authorization: Bearer $FIGMA_TOKEN"通过 读取 Figma 内容。用户的OAuth bearer token存储在
中;每次调用都需要携带请求头。基础URL:
。
curl + jq$FIGMA_TOKENAuthorization: Bearer $FIGMA_TOKENhttps://api.figma.com/v1失败响应格式为 —— 直接显示字段内容。表示令牌缺少权限范围,或文件未与用户共享。表示文件密钥无效。
{"status":<code>,"err":"..."}err403404文件密钥是粘贴的URL中或部分的内容。节点ID在URL的参数中(Figma界面显示为;API也接受格式)。
figma.com/file/<KEY>/...figma.com/design/<KEY>/...?node-id=1-231:231:23bash
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]}]}'
| jq '{name, pages: [.document.children[] | {name, frames: [.children[]?.name]}]}'
undefinedcurl -sS -H "$AUTH" "$F/files/FILE_KEY?depth=2"
| jq '{name, pages: [.document.children[] | {name, frames: [.children[]?.name]}]}'
| jq '{name, pages: [.document.children[] | {name, frames: [.children[]?.name]}]}'
undefinedRead 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}'
| 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}'
| 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" }
| 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" }
| 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'
undefinedcurl -sS -H "$AUTH" "$F/teams/TEAM_ID/projects" | jq '.projects'
undefinedGotchas
注意事项
- Node ids: Figma URLs use (dash); the API wants
1-23(colon). Convert.1:23 - URLs are temporary — download/use them promptly, don't store.
/images - limits tree traversal; omit it only for small files or you'll pull megabytes of node JSON.
depth=
- 节点ID:Figma URL使用(短横线);API要求使用
1-23(冒号),需进行转换。1:23 - 接口返回的链接是临时的 —— 请及时下载/使用,不要存储。
/images - 参数限制树遍历深度;仅在处理小文件时省略该参数,否则会拉取数MB的节点JSON数据。
depth=