figma_api/apis/
files_api.rs

1/*
2 * Figma API
3 *
4 * This is the OpenAPI specification for the [Figma REST API](https://www.figma.com/developers/api).  Note: we are releasing the OpenAPI specification as a beta given the large surface area and complexity of the REST API. If you notice any inaccuracies with the specification, please [file an issue](https://github.com/figma/rest-api-spec/issues).
5 *
6 * The version of the OpenAPI document: 0.31.0
7 * Contact: support@figma.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_file`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetFileError {
22    Status400(models::InlineObject16),
23    Status403(models::InlineObject19),
24    Status404(models::InlineObject21),
25    Status429(models::InlineObject23),
26    Status500(models::InlineObject25),
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`get_file_meta`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum GetFileMetaError {
34    Status400(models::InlineObject16),
35    Status403(models::InlineObject19),
36    Status404(models::InlineObject21),
37    Status429(models::InlineObject23),
38    Status500(models::InlineObject25),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_file_nodes`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetFileNodesError {
46    Status400(models::InlineObject16),
47    Status403(models::InlineObject19),
48    Status404(models::InlineObject21),
49    Status429(models::InlineObject23),
50    Status500(models::InlineObject25),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`get_image_fills`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum GetImageFillsError {
58    Status400(models::InlineObject16),
59    Status403(models::InlineObject19),
60    Status404(models::InlineObject21),
61    Status429(models::InlineObject23),
62    Status500(models::InlineObject25),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`get_images`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetImagesError {
70    Status400(models::InlineObject16),
71    Status403(models::InlineObject19),
72    Status404(models::InlineObject21),
73    Status429(models::InlineObject23),
74    Status500(models::InlineObject25),
75    UnknownValue(serde_json::Value),
76}
77
78
79/// Returns the document identified by `file_key` as a JSON object. The file key can be parsed from any Figma file url: `https://www.figma.com/file/{file_key}/{title}`.  The `document` property contains a node of type `DOCUMENT`.  The `components` property contains a mapping from node IDs to component metadata. This is to help you determine which components each instance comes from.
80pub async fn get_file(configuration: &configuration::Configuration, file_key: &str, version: Option<&str>, ids: Option<&str>, depth: Option<f64>, geometry: Option<&str>, plugin_data: Option<&str>, branch_data: Option<bool>) -> Result<models::InlineObject, Error<GetFileError>> {
81    // add a prefix to parameters to efficiently prevent name collisions
82    let p_file_key = file_key;
83    let p_version = version;
84    let p_ids = ids;
85    let p_depth = depth;
86    let p_geometry = geometry;
87    let p_plugin_data = plugin_data;
88    let p_branch_data = branch_data;
89
90    let uri_str = format!("{}/v1/files/{file_key}", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
91    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
92
93    if let Some(ref param_value) = p_version {
94        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
95    }
96    if let Some(ref param_value) = p_ids {
97        req_builder = req_builder.query(&[("ids", &param_value.to_string())]);
98    }
99    if let Some(ref param_value) = p_depth {
100        req_builder = req_builder.query(&[("depth", &param_value.to_string())]);
101    }
102    if let Some(ref param_value) = p_geometry {
103        req_builder = req_builder.query(&[("geometry", &param_value.to_string())]);
104    }
105    if let Some(ref param_value) = p_plugin_data {
106        req_builder = req_builder.query(&[("plugin_data", &param_value.to_string())]);
107    }
108    if let Some(ref param_value) = p_branch_data {
109        req_builder = req_builder.query(&[("branch_data", &param_value.to_string())]);
110    }
111    if let Some(ref user_agent) = configuration.user_agent {
112        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
113    }
114    if let Some(ref token) = configuration.oauth_access_token {
115        req_builder = req_builder.bearer_auth(token.to_owned());
116    };
117    if let Some(ref apikey) = configuration.api_key {
118        let key = apikey.key.clone();
119        let value = match apikey.prefix {
120            Some(ref prefix) => format!("{} {}", prefix, key),
121            None => key,
122        };
123        req_builder = req_builder.header("X-Figma-Token", value);
124    };
125
126    let req = req_builder.build()?;
127    let resp = configuration.client.execute(req).await?;
128
129    let status = resp.status();
130    let content_type = resp
131        .headers()
132        .get("content-type")
133        .and_then(|v| v.to_str().ok())
134        .unwrap_or("application/octet-stream");
135    let content_type = super::ContentType::from(content_type);
136
137    if !status.is_client_error() && !status.is_server_error() {
138        let content = resp.text().await?;
139        match content_type {
140            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
141            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject`"))),
142            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject`")))),
143        }
144    } else {
145        let content = resp.text().await?;
146        let entity: Option<GetFileError> = serde_json::from_str(&content).ok();
147        Err(Error::ResponseError(ResponseContent { status, content, entity }))
148    }
149}
150
151/// Get file metadata
152pub async fn get_file_meta(configuration: &configuration::Configuration, file_key: &str) -> Result<models::InlineObject4, Error<GetFileMetaError>> {
153    // add a prefix to parameters to efficiently prevent name collisions
154    let p_file_key = file_key;
155
156    let uri_str = format!("{}/v1/files/{file_key}/meta", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
157    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159    if let Some(ref user_agent) = configuration.user_agent {
160        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161    }
162    if let Some(ref token) = configuration.oauth_access_token {
163        req_builder = req_builder.bearer_auth(token.to_owned());
164    };
165    if let Some(ref apikey) = configuration.api_key {
166        let key = apikey.key.clone();
167        let value = match apikey.prefix {
168            Some(ref prefix) => format!("{} {}", prefix, key),
169            None => key,
170        };
171        req_builder = req_builder.header("X-Figma-Token", value);
172    };
173
174    let req = req_builder.build()?;
175    let resp = configuration.client.execute(req).await?;
176
177    let status = resp.status();
178    let content_type = resp
179        .headers()
180        .get("content-type")
181        .and_then(|v| v.to_str().ok())
182        .unwrap_or("application/octet-stream");
183    let content_type = super::ContentType::from(content_type);
184
185    if !status.is_client_error() && !status.is_server_error() {
186        let content = resp.text().await?;
187        match content_type {
188            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
189            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject4`"))),
190            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject4`")))),
191        }
192    } else {
193        let content = resp.text().await?;
194        let entity: Option<GetFileMetaError> = serde_json::from_str(&content).ok();
195        Err(Error::ResponseError(ResponseContent { status, content, entity }))
196    }
197}
198
199/// Returns the nodes referenced to by `ids` as a JSON object. The nodes are retrieved from the Figma file referenced to by `file_key`.  The node ID and file key can be parsed from any Figma node url: `https://www.figma.com/file/{file_key}/{title}?node-id={id}`  The `name`, `lastModified`, `thumbnailUrl`, `editorType`, and `version` attributes are all metadata of the specified file.  The `linkAccess` field describes the file link share permission level. There are 5 types of permissions a shared link can have: `\"inherit\"`, `\"view\"`, `\"edit\"`, `\"org_view\"`, and `\"org_edit\"`. `\"inherit\"` is the default permission applied to files created in a team project, and will inherit the project's permissions. `\"org_view\"` and `\"org_edit\"` restrict the link to org users.  The `document` attribute contains a Node of type `DOCUMENT`.  The `components` key contains a mapping from node IDs to component metadata. This is to help you determine which components each instance comes from.  By default, no vector data is returned. To return vector data, pass the geometry=paths parameter to the endpoint. Each node can also inherit properties from applicable styles. The styles key contains a mapping from style IDs to style metadata.  Important: the nodes map may contain values that are `null`. This may be due to the node id not existing within the specified file.
200pub async fn get_file_nodes(configuration: &configuration::Configuration, file_key: &str, ids: &str, version: Option<&str>, depth: Option<f64>, geometry: Option<&str>, plugin_data: Option<&str>) -> Result<models::InlineObject1, Error<GetFileNodesError>> {
201    // add a prefix to parameters to efficiently prevent name collisions
202    let p_file_key = file_key;
203    let p_ids = ids;
204    let p_version = version;
205    let p_depth = depth;
206    let p_geometry = geometry;
207    let p_plugin_data = plugin_data;
208
209    let uri_str = format!("{}/v1/files/{file_key}/nodes", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
210    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
211
212    req_builder = req_builder.query(&[("ids", &p_ids.to_string())]);
213    if let Some(ref param_value) = p_version {
214        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
215    }
216    if let Some(ref param_value) = p_depth {
217        req_builder = req_builder.query(&[("depth", &param_value.to_string())]);
218    }
219    if let Some(ref param_value) = p_geometry {
220        req_builder = req_builder.query(&[("geometry", &param_value.to_string())]);
221    }
222    if let Some(ref param_value) = p_plugin_data {
223        req_builder = req_builder.query(&[("plugin_data", &param_value.to_string())]);
224    }
225    if let Some(ref user_agent) = configuration.user_agent {
226        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
227    }
228    if let Some(ref token) = configuration.oauth_access_token {
229        req_builder = req_builder.bearer_auth(token.to_owned());
230    };
231    if let Some(ref apikey) = configuration.api_key {
232        let key = apikey.key.clone();
233        let value = match apikey.prefix {
234            Some(ref prefix) => format!("{} {}", prefix, key),
235            None => key,
236        };
237        req_builder = req_builder.header("X-Figma-Token", value);
238    };
239
240    let req = req_builder.build()?;
241    let resp = configuration.client.execute(req).await?;
242
243    let status = resp.status();
244    let content_type = resp
245        .headers()
246        .get("content-type")
247        .and_then(|v| v.to_str().ok())
248        .unwrap_or("application/octet-stream");
249    let content_type = super::ContentType::from(content_type);
250
251    if !status.is_client_error() && !status.is_server_error() {
252        let content = resp.text().await?;
253        match content_type {
254            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
255            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject1`"))),
256            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject1`")))),
257        }
258    } else {
259        let content = resp.text().await?;
260        let entity: Option<GetFileNodesError> = serde_json::from_str(&content).ok();
261        Err(Error::ResponseError(ResponseContent { status, content, entity }))
262    }
263}
264
265/// Returns download links for all images present in image fills in a document. Image fills are how Figma represents any user supplied images. When you drag an image into Figma, we create a rectangle with a single fill that represents the image, and the user is able to transform the rectangle (and properties on the fill) as they wish.  This endpoint returns a mapping from image references to the URLs at which the images may be download. Image URLs will expire after no more than 14 days. Image references are located in the output of the GET files endpoint under the `imageRef` attribute in a `Paint`.
266pub async fn get_image_fills(configuration: &configuration::Configuration, file_key: &str) -> Result<models::InlineObject3, Error<GetImageFillsError>> {
267    // add a prefix to parameters to efficiently prevent name collisions
268    let p_file_key = file_key;
269
270    let uri_str = format!("{}/v1/files/{file_key}/images", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
271    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
272
273    if let Some(ref user_agent) = configuration.user_agent {
274        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
275    }
276    if let Some(ref token) = configuration.oauth_access_token {
277        req_builder = req_builder.bearer_auth(token.to_owned());
278    };
279    if let Some(ref apikey) = configuration.api_key {
280        let key = apikey.key.clone();
281        let value = match apikey.prefix {
282            Some(ref prefix) => format!("{} {}", prefix, key),
283            None => key,
284        };
285        req_builder = req_builder.header("X-Figma-Token", value);
286    };
287
288    let req = req_builder.build()?;
289    let resp = configuration.client.execute(req).await?;
290
291    let status = resp.status();
292    let content_type = resp
293        .headers()
294        .get("content-type")
295        .and_then(|v| v.to_str().ok())
296        .unwrap_or("application/octet-stream");
297    let content_type = super::ContentType::from(content_type);
298
299    if !status.is_client_error() && !status.is_server_error() {
300        let content = resp.text().await?;
301        match content_type {
302            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
303            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject3`"))),
304            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject3`")))),
305        }
306    } else {
307        let content = resp.text().await?;
308        let entity: Option<GetImageFillsError> = serde_json::from_str(&content).ok();
309        Err(Error::ResponseError(ResponseContent { status, content, entity }))
310    }
311}
312
313/// Renders images from a file.  If no error occurs, `\"images\"` will be populated with a map from node IDs to URLs of the rendered images, and `\"status\"` will be omitted. The image assets will expire after 30 days. Images up to 32 megapixels can be exported. Any images that are larger will be scaled down.  Important: the image map may contain values that are `null`. This indicates that rendering of that specific node has failed. This may be due to the node id not existing, or other reasons such has the node having no renderable components. It is guaranteed that any node that was requested for rendering will be represented in this map whether or not the render succeeded.  To render multiple images from the same file, use the `ids` query parameter to specify multiple node ids.  ``` GET /v1/images/:key?ids=1:2,1:3,1:4 ``` 
314pub async fn get_images(configuration: &configuration::Configuration, file_key: &str, ids: &str, version: Option<&str>, scale: Option<f64>, format: Option<&str>, svg_outline_text: Option<bool>, svg_include_id: Option<bool>, svg_include_node_id: Option<bool>, svg_simplify_stroke: Option<bool>, contents_only: Option<bool>, use_absolute_bounds: Option<bool>) -> Result<models::InlineObject2, Error<GetImagesError>> {
315    // add a prefix to parameters to efficiently prevent name collisions
316    let p_file_key = file_key;
317    let p_ids = ids;
318    let p_version = version;
319    let p_scale = scale;
320    let p_format = format;
321    let p_svg_outline_text = svg_outline_text;
322    let p_svg_include_id = svg_include_id;
323    let p_svg_include_node_id = svg_include_node_id;
324    let p_svg_simplify_stroke = svg_simplify_stroke;
325    let p_contents_only = contents_only;
326    let p_use_absolute_bounds = use_absolute_bounds;
327
328    let uri_str = format!("{}/v1/images/{file_key}", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
329    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
330
331    req_builder = req_builder.query(&[("ids", &p_ids.to_string())]);
332    if let Some(ref param_value) = p_version {
333        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
334    }
335    if let Some(ref param_value) = p_scale {
336        req_builder = req_builder.query(&[("scale", &param_value.to_string())]);
337    }
338    if let Some(ref param_value) = p_format {
339        req_builder = req_builder.query(&[("format", &param_value.to_string())]);
340    }
341    if let Some(ref param_value) = p_svg_outline_text {
342        req_builder = req_builder.query(&[("svg_outline_text", &param_value.to_string())]);
343    }
344    if let Some(ref param_value) = p_svg_include_id {
345        req_builder = req_builder.query(&[("svg_include_id", &param_value.to_string())]);
346    }
347    if let Some(ref param_value) = p_svg_include_node_id {
348        req_builder = req_builder.query(&[("svg_include_node_id", &param_value.to_string())]);
349    }
350    if let Some(ref param_value) = p_svg_simplify_stroke {
351        req_builder = req_builder.query(&[("svg_simplify_stroke", &param_value.to_string())]);
352    }
353    if let Some(ref param_value) = p_contents_only {
354        req_builder = req_builder.query(&[("contents_only", &param_value.to_string())]);
355    }
356    if let Some(ref param_value) = p_use_absolute_bounds {
357        req_builder = req_builder.query(&[("use_absolute_bounds", &param_value.to_string())]);
358    }
359    if let Some(ref user_agent) = configuration.user_agent {
360        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
361    }
362    if let Some(ref token) = configuration.oauth_access_token {
363        req_builder = req_builder.bearer_auth(token.to_owned());
364    };
365    if let Some(ref apikey) = configuration.api_key {
366        let key = apikey.key.clone();
367        let value = match apikey.prefix {
368            Some(ref prefix) => format!("{} {}", prefix, key),
369            None => key,
370        };
371        req_builder = req_builder.header("X-Figma-Token", value);
372    };
373
374    let req = req_builder.build()?;
375    let resp = configuration.client.execute(req).await?;
376
377    let status = resp.status();
378    let content_type = resp
379        .headers()
380        .get("content-type")
381        .and_then(|v| v.to_str().ok())
382        .unwrap_or("application/octet-stream");
383    let content_type = super::ContentType::from(content_type);
384
385    if !status.is_client_error() && !status.is_server_error() {
386        let content = resp.text().await?;
387        match content_type {
388            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
389            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject2`"))),
390            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject2`")))),
391        }
392    } else {
393        let content = resp.text().await?;
394        let entity: Option<GetImagesError> = serde_json::from_str(&content).ok();
395        Err(Error::ResponseError(ResponseContent { status, content, entity }))
396    }
397}
398