Api figma
To export layers as images from Figma using the REST API, you use the GET Image endpoint.
✅ Step-by-Step: Export Layers as Images
๐ Prerequisites:
- Figma File Key – from the file URL:
https://www.figma.com/file/**FILE_KEY**/...
- Node IDs – the layer(s) you want to export
- Personal Access Token – from Figma account settings
๐งช 1. Get Node IDs (Layer IDs)
Endpoint:
GET https://api.figma.com/v1/files/{file_key}
- Returns a full file structure (
document
) - Traverse the JSON to find
id
of the nodes/layers you want to export (e.g., text, image, button, frame)
Example node ID:
"25:12"
๐ผ️ 2. Export Node as Image
Endpoint:
GET https://api.figma.com/v1/images/{file_key}
Query Parameters:
ids
: Comma-separated node IDsformat
:png
,jpg
, orsvg
scale
: optional, defaults to 1 (can be 2 for high-res)use_absolute_bounds
: optional for exporting only visible area
Example Request:
GET https://api.figma.com/v1/images/AbCDeFGHIjkL?ids=25:12&format=png
Authorization: Bearer YOUR_FIGMA_PERSONAL_ACCESS_TOKEN
Response:
{
"images": {
"25:12": "https://s3-alpha.figma.com/exports/..."
}
}
๐พ 3. Download the Exported Image
- Use the returned URL to download the PNG/SVG/JPG
- The URL is public but temporary, valid for a few minutes
✅ C# Example (using HttpClient
)
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", "YOUR_ACCESS_TOKEN");
var fileKey = "YOUR_FILE_KEY";
var nodeId = "25:12";
var url = $"https://api.figma.com/v1/images/{fileKey}?ids={nodeId}&format=png";
var response = await client.GetAsync(url);
var json = await response.Content.ReadAsStringAsync();
var imageUrl = JsonDocument.Parse(json)
.RootElement.GetProperty("images").GetProperty(nodeId).GetString();
// Now download the image
var imageBytes = await client.GetByteArrayAsync(imageUrl);
File.WriteAllBytes("exported.png", imageBytes);
๐ Notes
- You cannot export entire pages—only specific layers/frames via their Node IDs
- You must have access to the file
- For component sets or nested layers, use recursion to get node IDs
Would you like a working WPF UI or tool that lets you select and export layers as images from Figma?
Comments
Post a Comment