The `figma-api` package provides a thin, typed JavaScript/TypeScript wrapper around the official Figma REST API. Currently in its 2.1.2-beta version, this library offers a client-side implementation designed for both browser and Node.js environments. It leverages Promises via Axios for HTTP requests and is fully typed with TypeScript, aligning its API methods directly with the official Figma REST API specifications. A significant rewrite occurred in version 2.x, standardizing endpoint method names and argument structures to precisely match Figma's documentation, ensuring future consistency. The package differentiates itself by closely mirroring the official API spec, providing a robust, type-safe interface for interacting with Figma files and resources programmatically, making it easier for developers to build integrations without constantly referring to external documentation for method signatures.
npm install figma-apiVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the Figma API client with a personal access token, fetch a specific Figma file by its key, and then log some basic information about the retrieved file structure, handling potential errors.
Refer to the official Figma REST API documentation for updated method names and argument structures. Update all API calls to match the new object-based parameter passing (e.g., `api.getFile({ file_key: '...' })`).Monitor the project's GitHub releases and NPM for stable version announcements. For production applications, consider locking to a specific beta version or preparing for minor updates.
For browser usage, it is recommended to install the library via npm (`npm i figma-api`) and bundle it with your application. Alternatively, ensure your server-side proxy handles CORS headers correctly, or configure your Figma API client with a proxy if available.
Ensure you are using a valid personal access token obtained from Figma, or correctly implementing the OAuth 2.0 flow to acquire and refresh access tokens. Verify that the token has the necessary permissions (scopes) for the desired API operations.
Use a namespace import: `import * as Figma from 'figma-api';` and then access the class as `new Figma.Api(...)`. If using CommonJS, which is not officially supported for modern versions, module interop might be needed or consider transpiling.
Ensure your code uses the v2.x API method names and argument structures, which expect parameters to be passed within objects (e.g., `api.getFile({ file_key: '...' })`). Consult the official Figma REST API documentation for correct endpoint signatures.Verify that your Figma token is correct, not expired, and has the required 'file_read' or other necessary scopes for the API call you are making. Generate a new token from Figma settings if unsure.
If in a browser, ensure your application's origin is allowed by Figma (which it generally is for standard API calls) or that your browser environment isn't imposing stricter local policies. For Node.js, check network connectivity. If using a direct CDN link in the browser, consider bundling with npm to mitigate CORS, or implement a proxy.