This playbook outlines the steps taken to export design assets from a Figma file to a specified format using the Figma API.
curl
andjq
installed on the local machine.- A bash shell environment.
-
Check if a Figma access token is present in the
.env
orsecret.txt
file. If so, use that token. -
If the Figma access token is not found in the
.env
orsecret.txt
file, prompt the user to enter the access token.
- If the conversion format was not specified earlier, prompt the user to enter the desired export format (e.g., PNG, SVG, PDF).
- If the export scope was not specified earlier, prompt the user to specify what to export (i.e., whole page, frames, or individual components).
- If there are multiple file URLs, replicate the following steps for each URL:
-
Create seperate a new directory for each file url.
-
Run command based on the view and format requested by the user.
-
For full page view :
- use id = 0:1
curl -H 'X-Figma-Token: <user-token>' 'https://api.figma.com/v1/images/<file-key>?format=<format>&ids=0:1'
-
For all frames view:
- Parse the JSON structure and extract the node IDs for the frames to be exported by "type":"FRAME" .
- Then make request in a single curl command with all the frame ids
curl -H 'X-Figma-Token: <user-token>' 'https://api.figma.com/v1/images/<file-key>?format=<format>&ids=<frame-id>'
-
For all components view:
- Parse the JSON structure and extract all the node IDs of any type.
- Then make request in a single curl command with all ids
curl -H 'X-Figma-Token: <user-token>' 'https://api.figma.com/v1/images/<file-key>?format=<format>&ids=<frame-id>'
-
For image fills view:
curl -H 'X-Figma-Token: <user-token>' 'https://api.figma.com/v1/images/<file-key>/images?format=<format>'
-
Parse the JSON returned from the curl command.
-
Download the images using the links.
-
Save the images in the desired format.
-
Rename the file with the proper name, format and extension.
-
-
- After checking all files, if no errors were found, inform the user that all the exported files match.
-
Package the converted files into a zip file for the user.
-
Send the zip file as an attachment using the messaging interface to the browser.
-
Check if the files are accessible by attempting to download or open each file.
-
If all files are accessible, inform the user about the availability of the zip file using the messaging interface to the browser.
-
Obtain the Figma access token from the user or a secure source.
-
Prompt the user to specify the desired export format (e.g., PNG, SVG, PDF).
-
Prompt the user to specify the export scope (e.g., whole page, frames, or individual components).
-
Handle multiple file URLs by repeating the following steps for each URL:
-
Retrieve the Figma file structure using the file key.
-
Parse the JSON structure and extract the node IDs for the frames or layers to be exported.
-
Export the specified elements in the desired format.
-
-
Package the converted files into a zip file for the user.
-
Ensure that the converted files are sent using the messaging interface to the browser.
-
Inform the user about the availability of the zip file and the hosted files for verification.
- Do not overwrite files without permission.
- Refer to the Figma API documentation for detailed information on API endpoints and export settings.
- Adjust export settings via API as needed: file name, resolution, scaling.
- Verify exported files for correct format and quality before final delivery.
- Test exported files in the intended environment (e.g., web, print).