Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save R-ohit-B-isht/ee1dc81a8d32b6899be5c9bb25de7719 to your computer and use it in GitHub Desktop.
Save R-ohit-B-isht/ee1dc81a8d32b6899be5c9bb25de7719 to your computer and use it in GitHub Desktop.

Playbook: Exporting Figma Files to Specified Format Playbook

Overview

This playbook outlines the steps taken to export design assets from a Figma file to a specified format using the Figma API.

Prerequisites

  • curl and jq installed on the local machine.
  • A bash shell environment.

Procedure

1. Obtain Figma Access Token

  • Check if a Figma access token is present in the .env or secret.txt file. If so, use that token.

  • If the Figma access token is not found in the .env or secret.txt file, prompt the user to enter the access token.

2. Specify Conversion Format

  • If the conversion format was not specified earlier, prompt the user to enter the desired export format (e.g., PNG, SVG, PDF).

3. Specify Export Scope

  • If the export scope was not specified earlier, prompt the user to specify what to export (i.e., whole page, frames, or individual components).

4. Handle Multiple File URLs

  • 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.

5. Verify Exported Files

  • After checking all files, if no errors were found, inform the user that all the exported files match.

6. Provide Conversion Verification

  • 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.

Task Requirements

  1. Obtain the Figma access token from the user or a secure source.

  2. Prompt the user to specify the desired export format (e.g., PNG, SVG, PDF).

  3. Prompt the user to specify the export scope (e.g., whole page, frames, or individual components).

  4. 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.

  5. Package the converted files into a zip file for the user.

  6. Ensure that the converted files are sent using the messaging interface to the browser.

  7. Inform the user about the availability of the zip file and the hosted files for verification.

Advice and Pointers

  • 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment