Figma API
Basic API client for Figma. You can find some usage examples in these references:
typescript
declare function createFigmaApi(params: CreateFigmaApiParams): FigmaApi;
const figma = createFigmaApi({
/* ... */
});declare function createFigmaApi(params: CreateFigmaApiParams): FigmaApi;
const figma = createFigmaApi({
/* ... */
});CreateFigmaApiParams
typescript
export interface CreateFigmaApiParams {
/**
* The base URL of the Figma API (with version).
* @default 'https://api.figma.com/v1'
*/
baseUrl?: string;
/**
* The fetch function to use.
* @default globalThis.fetch
* @attention Will be replaced with our fetch client in the future.
*/
fetch?: typeof fetch;
/**
* The logger implementation.
* @see `@neodx/logger`
* @default Logger with `debug` level.
*/
log?: LoggerMethods<'info' | 'error' | 'debug'>;
/**
* The access token of the Figma API (OAuth2).
* @see https://www.figma.com/developers/api#access-tokens
*/
accessToken?: string;
/**
* The personal access token of the Figma API.
* @default process.env.FIGMA_TOKEN
* @see https://www.figma.com/developers/api#access-tokens
*/
personalAccessToken?: string;
}export interface CreateFigmaApiParams {
/**
* The base URL of the Figma API (with version).
* @default 'https://api.figma.com/v1'
*/
baseUrl?: string;
/**
* The fetch function to use.
* @default globalThis.fetch
* @attention Will be replaced with our fetch client in the future.
*/
fetch?: typeof fetch;
/**
* The logger implementation.
* @see `@neodx/logger`
* @default Logger with `debug` level.
*/
log?: LoggerMethods<'info' | 'error' | 'debug'>;
/**
* The access token of the Figma API (OAuth2).
* @see https://www.figma.com/developers/api#access-tokens
*/
accessToken?: string;
/**
* The personal access token of the Figma API.
* @default process.env.FIGMA_TOKEN
* @see https://www.figma.com/developers/api#access-tokens
*/
personalAccessToken?: string;
}FigmaApi
For details about the Figma API, see Figma API Reference or our Types for Figma API.
Files
getFile({ id, ...params }: GetFileParams): GetFileResultgetFileNodes<Node extends AnyNode>({ id, ...params }: GetFileNodesParams): GetFileNodesResult<Node>getImage({ id, ...params }: GetImageParams):GetImageResultgetImageFills({ id }: GetImageFillsParams):GetImageFillsResult
Comments
getComments({ id }: GetCommentsParams):GetCommentsResultpostComments({ id, ...body }: PostCommentsParams):PostCommentResultdeleteComments({ id, comment_id }: DeleteCommentsParams):void
Users
getMe():GetUserMeResult
Versions
getVersions({ id }: GetVersionsParams):GetVersionsResult
Teams and projects
getTeamProjects({ team_id }: GetTeamProjectsParams):GetTeamProjectsResultGET /v1/teams/:team_id/projects
getProjectFiles({ project_id }: GetProjectFilesParams):GetProjectFilesResultGET /v1/projects/:project_id/files
Components and styles
WARNING
These APIs are required at least Figma Professional plan
getTeamComponents({ team_id }: GetTeamComponentsParams):GetTeamComponentsResultGET /v1/teams/:team_id/components
getFileComponents({ id }: GetFileComponentsParams):GetFileComponentsResultGET /v1/files/:file_key/components
getComponent({ key }: GetComponentParams):GetComponentResultGET /v1/components/:key
getTeamComponentSets({ team_id }: GetTeamComponentSetsParams):GetTeamComponentSetsResultGET /v1/teams/:team_id/component_sets
getFileComponentSets({ id }: GetFileComponentSetsParams):GetFileComponentSetsResultGET /v1/files/:file_key/component_sets
getComponentSet({ key }: GetComponentSetParams):GetComponentSetResultGET /v1/component_sets/:key
getTeamStyles({ team_id }: GetTeamStylesParams):GetTeamStylesResultGET /v1/teams/:team_id/styles
getFileStyles({ id }: GetFileStylesParams):GetFileStylesResultGET /v1/files/:file_key/styles
getStyle({ key }: GetStyleParams):GetStyleResultGET /v1/styles/:key
Variables
Not ready
Work in progress...
Neodx