Skip to main content

I’m able to get an image with the image rest api (GET https://api.figma.com/v1/images/:key?ids=:node_id), but it doesn’t crop the result to the provided node id. Instead, it renders everything below the top layer the node is nested under.

This is what I receive from the api.

This is what I want from the api roughly.

 

Is it possible to get the desired result from this api, or do I need to explore alternatives? The node ids I’m using are derived from the url after clicking on the node in the figma viewer (www.figma.com/design/{file_id}/{file_name}?node-id={node_id}).

You need to use the correct node ID. As far as I understand, you got the ID of the top-level frame (the node that is directly on the canvas), so the output is a link to the full frame image. Note that the URL does not change when selecting nested (child) layers, it displays the ID of exactly the top-level node. So get the ID you need using other REST API endpoints or Plugin API.


Ah. That was the issue. I was clicking layers and saw it changing, but didn’t look closely enough to notice that the id wasn’t changing when switching between sub layers. Confirmed that the image is returned as expected after using the correct id provided by the api.


Reply