Install and Auth
Figmage talks to the Figma REST API on your behalf, so it needs two pieces of information:
- A personal access token that authorizes API requests.
- The file ID of the published Figma library you want to sync from.
Install Figmage
Section titled “Install Figmage”Install it as a dev dependency in your project:
npm install --save-dev figmage dotenvOr run it on demand without installing:
npx figmage syncYou can also install it globally if you prefer a system-wide command:
npm install -g figmageCreate a Figma API access token
Section titled “Create a Figma API access token”A personal access token lets Figmage read your file through the REST API.
-
Sign in to Figma and open Settings (click your avatar in the top-left, then Settings).
-
Go to the Security tab.
-
Under Personal access tokens, click Generate new token.
-
Give the token a descriptive name (for example
figmage). -
Set the File content scope to at least Read-only. This is the scope Figmage needs to read styles, components, and images.
-
Click Generate token and copy the token immediately — Figma only shows it once.
For reference, see Figma’s docs on access tokens.
Find your Figma file ID
Section titled “Find your Figma file ID”The file ID is part of the file URL. Open the file in Figma and look at the address bar:
https://www.figma.com/design/<fileId>/<file-name>?node-id=...The <fileId> segment (a long alphanumeric string right after /design/ or /file/) is the value
Figmage needs.
Store credentials with dotenv
Section titled “Store credentials with dotenv”Keep secrets out of your config file by loading them from the environment. Create a .env file in
your project root:
FIGMA_ACCESS_TOKEN="figd_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"FIGMA_FILE_ID="xxxxxxxxxxxxxxxxxxxxxx"Add .env to your .gitignore so it is never committed.
The examples below use dotenv, so install it alongside Figmage if your project does not already
include it.
Wire credentials into the config
Section titled “Wire credentials into the config”Figmage reads its configuration from figmage.config.js. Load the env file at the top and pass the
values to defineConfig:
import "dotenv/config";import { defineConfig } from "figmage";
export default defineConfig({ accessToken: process.env.FIGMA_ACCESS_TOKEN, fileId: process.env.FIGMA_FILE_ID, tokens: [{ name: "colors", type: "color" }],});accessToken and fileId are both required. If either is missing, figmage sync exits with an
error before making any requests.
For a complete automation workflow, see CI.
Custom config path
Section titled “Custom config path”The default config path is figmage.config.js in the current working directory. Point to another
location with --config:
figmage sync --config ./configs/figmage.config.js