To fetch and manipulate text node properties using the Figma REST API, you can follow these steps:
1. Fetch the file nodes: Use the "GET file nodes" endpoint to retrieve the nodes in a Figma file. This will give you the node data, including text nodes.
GET https://api.figma.com/v1/files/FILE_KEY/nodes?ids=NODE_ID
2. Identify text nodes: In the response, look for nodes with a `type` of `"TEXT"`. These are the text nodes.
3. Fetch text node properties: You can then access the various text properties of the text nodes, such as `fontSize`, `fontName`, `textCase`, `textDecoration`, `letterSpacing`, `lineHeight`, and more. These properties are available in the `styles` object of the text node.
For example, to get the font size and font name of a text node:
json
{
"nodes": {
"NODE_ID": {
"type": "TEXT",
"styles": {
"fontSize": 16,
"fontName": {
"family": "Inter",
"style": "Regular"
}
}
}
}
}
4. Update text node properties: To update the text node properties, you can use the "Update node" endpoint and provide the new values for the properties you want to change.
PATCH https://api.figma.com/v1/files/FILE_KEY/nodes/NODE_ID
{
"properties": {
"fontSize": 18,
"fontName": {
"family": "Roboto",
"style": "Bold"
}
}
}
Keep in mind that updating certain properties, such as `fontName`, may require the new font to be loaded in the Figma file.
By following these steps, you can use the Figma REST API to fetch and manipulate the text node properties in your Figma files. The key is to use the "GET file nodes" endpoint to retrieve the node data, identify the text nodes, and then update the properties as needed using the "Update node" endpoint.[2][3][4][5]
Citations:[1] https://stackoverflow.com/questions/76826875/nodes-from-figma-rest-api-dont-have-visible-property
[2] https://www.figma.com/developers/api
[3] https://forum.figma.com/t/get-text-from-component-using-rest-api/53208
[4] https://www.figma.com/plugin-docs/api/TextNode/
[5] https://forum.figma.com/t/rest-api-get-color-and-text-styles/49216