I’m building a script to scan through Figma files in a workspace and locate specific node types. I’m using the figma-api npm library which wraps the official Figma REST API.
The API docs show that the GET files endpoint should return the complete document as JSON. This JSON contains a node tree structure representing the whole Figma file.
However, when I try to fetch one of my larger files, I keep getting this error:
const figmaClient = new FigmaAPI({
personalAccessToken: 'your-token-here'
});
async function fetchDesignFile(documentId) {
try {
const response = await figmaClient.getFile(documentId);
return response.data;
} catch (error) {
console.error('Failed to retrieve file:', error.message);
// Error: Request failed with status code 400
// Response data: { status: 400, err: 'Render timeout, try requesting fewer or smaller images' }
}
}
The weird part is the error message mentions images and rendering timeouts, but I’m just trying to get the document structure as JSON. There’s a separate endpoint for images.
Is there any way to successfully retrieve large Figma files through the API? Maybe I need to fetch the data in smaller pieces somehow?