Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class FigmaClient
- Object
- FigmaClient
Fetches a file from Figma’s REST API and reads it into an ArtDocument.
The token is a personal access token (or OAuth token) the user supplies. It is kept only
in this object, sent only to api.figma.com in the X-Figma-Token header, and never
stored or logged. Requests block until they finish, so call from a background thread or
through invokeAndBlock.
String token = "PERSONAL_ACCESS_TOKEN"; // typed by the user, never stored
Display.getInstance().startThread(() -> {
try {
ArtDocument doc = new FigmaClient(token).fetch("FILE_KEY_FROM_THE_URL");
Log.p("Layers: " + doc.getRoot().getChildren().size());
} catch (IOException err) {
Log.e(err);
}
}, "figma").start();Fields
public static final String API = "https://api.figma.com/v1/" | The API this client talks to. |
public static final int MAX_IMAGES = 1000 | The most image fills downloaded for one file. |
Constructors
public FigmaClient(String token) | Creates a client. |
Methods
public FigmaClient setOAuth(boolean oauth) | Sends the token as an OAuth bearer token instead of a personal access token. |
public ArtDocument fetch(String fileKey)
throws IOException | Fetches a file with its geometry and image fills and reads it. |
public byte[] get(String path)
throws IOException | The raw JSON of any API path, such as files/KEY/nodes?ids=1:2&geometry=paths. |
Inherited methods
Field details
API
public static final String API = "https://api.figma.com/v1/"The API this client talks to.
MAX_IMAGES
public static final int MAX_IMAGES = 1000The most image fills downloaded for one file.
Constructor details
FigmaClient
public FigmaClient(String token)Creates a client.
Parameters
tokenString- a personal access token
Method details
setOAuth
public FigmaClient setOAuth(boolean oauth)Sends the token as an OAuth bearer token instead of a personal access token.
Parameters
oauthboolean- true for an OAuth token
fetch
public ArtDocument fetch(String fileKey)
throws IOExceptionFetches a file with its geometry and image fills and reads it.
Parameters
fileKeyString- the key in the file’s URL,
figma.com/design/KEY/...
Throws
get
public byte[] get(String path)
throws IOExceptionThe raw JSON of any API path, such as
files/KEY/nodes?ids=1:2&geometry=paths.Parameters
pathString- the path after
/v1/