getLocalPaintStyles() but for libraries?

I’m trying to get all the paint styles from a team library in my personal file. I see that there is getLocalPaintStyles() to get local styles but I’m not sure how to use this same behavior to grab all the library styles. Is there an equivalent for getting shared library styles?

2 Likes

Unfortunately there isn’t the equivalent API method for libraries. To accomplish this you’ll need to find a way to get the keys of all the paint styles you want from the file which is your library and import them using importStyleByKeyAsync().

You could hardcode these keys into your plugin or you could host them on a server. It’s a bit of a faff but the only way I’m aware of at the moment.

1 Like

Thanks for the info Gavin! Appreciate the help.

You can fetch those keys via the REST API, from the end point
https://api.figma.com/v1/files/<FILE KEY>/styles
You’ll need authentication, via an API key, for a user with view access to that file.

3 Likes

It is very unpractical to make authenticated Figma REST API calls from a plugin (unless I’m missing something). Is there a particular reason plugins cannot easily access library styles? Is there an ETA to provide an API method?

IMHO, this is critical to enable plugins to reuse styles and enable their configuration through styles. The Figma plugin development experience is already quite limited, but this even prevents basic modularity and reuse principles which contradicts Figma’s user experience.

For example, a plugin could provide the construction of a specific set of nodes based on some styles available in the document (colors, font styles), which could be (and mostly are) referenced from a library. Without an easy way to access them, plugin developers have to provide a setup UI (colors, font styles) that forces users to repeat their styling.

10 Likes

Having to perform the REST API call when the current file already has the info available is also fairly weird in a plugin context. A getRemotePaintStyles(FILE_KEY) (same for text etc…) method would be much better for plugin creation.

8 Likes