Skip to main content
Question

getLocalPaintStyles() but for libraries?


Alayna_Truttmann

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?

7 replies

Gavin
  • Active Member
  • 29 replies
  • March 1, 2021

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.


Alayna_Truttmann

Thanks for the info Gavin! Appreciate the help.


Finch
  • 15 replies
  • March 3, 2021

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.


David_Bonnet

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.


Benoit_Rajalu

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.


FlorianModel

Really a shame to be honest. @Figma_Support Is there a timeline on an API update?


vernikr
  • 7 replies
  • January 27, 2024

So how do plugins like Style Organizer https://www.figma.com/community/plugin/816627069580757929 manage to get all remote library styles?


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings