get_figma_page {figma}R Documentation

Get data of a specific canvas/page in a Figma File from the API

Description

This function uses the /v1/files/ endpoint of Figma API to get the data of an specific canvas/page (or a set of canvas/pages) from a Figma file, and fit it into a R object.

Usage

get_figma_page(
  file_key,
  token,
  node_ids,
  geometry = FALSE,
  .output_format = "response",
  ...
)

Arguments

file_key

A string with the key of the Figma File you want to get;

token

A string with your personal Figma token to authenticate in the API;

node_ids

A string with the node ID (or a vector of strings with node IDs);

geometry

A boolean value indicating if you want to export vector data. Defaults to FALSE;

.output_format

The output format. Options are "response", "figma_document", "tibble". Defaults to "response";

...

Further arguments that are passed to parse_response_object();

Details

With 'get_figma_file()' you get data of all objects in all canvas/pages of your Figma file. But with 'get_figma_page()' you get data of all objects drawn in a specific set of canvas/pages of your Figma file.

Every canvas/page in a Figma file, is identified by a node ID. You can easily get this ID from the URL that appears in your browser when you access this canvas/page on the Figma platform (See vignette("figma") for more details).

After you collected this node ID, give it to node_id argument as a string. If you want to collect data from more than one canvas/page of your Figma file, give a vector of node IDs to node_id argument.

Value

By default, get_figma_page() do not parse the output from the API, and returns the raw response object produced by the httr HTTP methods (e.g. httr::GET()).

But you can change this behavior with .output_format argument. With .output_format = "tibble", a tibble::tibble() object is returned. With .output_format = "figma_document", a object of class figma_document is returned (See Details section for more information).

Be aware of possible HTTP errors

To get the data of your Figma file, the functions from figma package make a HTTP request to the Figma API. But this request can fail for a number of reasons, and if this does happen, get_figma_page() will use report_http_error() to raise an error and report to the user, what kind of error message the Figma API returned. See vignette("http-errors") for more details.

Examples

## Not run: 
library(figma)
file_key <- "hch8YlkgaUIZ9raDzjPvCz"
token <- "my figma token secret ... "
node_id <- "0%3A1"
result <- figma::get_figma_page(
  file_key, token, node_id
)

## End(Not run)

[Package figma version 0.2.0 Index]