Skip to main content

firefly_iii/apis/
user_groups_api.rs

1/*
2 * Firefly III API v6.4.14
3 *
4 * This is the documentation of the Firefly III API. Please report any bugs or issues. You may use the \"Authorize\" button to try the API below. <br><br> Please keep in mind that the demo site does **not** accept requests from `curl`, `colly`, `wget`, etc. You must use a browser or a tool like Insomnia to make your test requests. <br><br> To learn more about the idiosyncrasies of this API, please read about the API in the [Firefly III API documentation](https://docs.firefly-iii.org/references/firefly-iii/api/). <br><br> <small>This file was last generated on 2025-12-26 @ 15:17:41 (Europe/Amsterdam)</small>
5 *
6 * The version of the OpenAPI document: v6.4.14
7 * Contact: james@firefly-iii.org
8 * Generated by: https://openapi-generator.tech
9 */
10
11#![allow(unused_imports)]
12
13use reqwest;
14
15use super::{configuration, Error};
16use crate::apis::ResponseContent;
17use crate::models::{self, *};
18
19/// struct for typed errors of method [`get_user_group`]
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(untagged)]
22pub enum GetUserGroupError {
23    Status401(models::UnauthenticatedResponse),
24    Status404(models::NotFoundResponse),
25    Status400(models::BadRequestResponse),
26    Status500(models::InternalExceptionResponse),
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`list_user_groups`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ListUserGroupsError {
34    Status401(models::UnauthenticatedResponse),
35    Status404(models::NotFoundResponse),
36    Status400(models::BadRequestResponse),
37    Status500(models::InternalExceptionResponse),
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`update_user_group`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum UpdateUserGroupError {
45    Status401(models::UnauthenticatedResponse),
46    Status404(models::NotFoundResponse),
47    Status400(models::BadRequestResponse),
48    Status500(models::InternalExceptionResponse),
49    Status422(models::ValidationErrorResponse),
50    UnknownValue(serde_json::Value),
51}
52
53/// Returns a single user group by its ID.
54pub async fn get_user_group(
55    configuration: &configuration::Configuration,
56    id: &str,
57    x_trace_id: Option<&str>,
58) -> Result<models::UserGroupSingle, Error<GetUserGroupError>> {
59    let local_var_configuration = configuration;
60
61    let local_var_client = &local_var_configuration.client;
62
63    let local_var_uri_str = format!(
64        "{}/v1/user-groups/{id}",
65        local_var_configuration.base_path,
66        id = crate::apis::urlencode(id)
67    );
68    let mut local_var_req_builder =
69        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
70
71    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
72        local_var_req_builder =
73            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
74    }
75    if let Some(local_var_param_value) = x_trace_id {
76        local_var_req_builder =
77            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
78    }
79    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
80        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
81    };
82    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
83        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
84    };
85
86    let local_var_req = local_var_req_builder.build()?;
87    let local_var_resp = local_var_client.execute(local_var_req).await?;
88
89    let local_var_status = local_var_resp.status();
90    let local_var_content = local_var_resp.text().await?;
91
92    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
93        serde_json::from_str(&local_var_content).map_err(Error::from)
94    } else {
95        let local_var_entity: Option<GetUserGroupError> =
96            serde_json::from_str(&local_var_content).ok();
97        let local_var_error = ResponseContent {
98            status: local_var_status,
99            content: local_var_content,
100            entity: local_var_entity,
101        };
102        Err(Error::ResponseError(local_var_error))
103    }
104}
105
106/// List all the user groups available to this user. These are essentially the 'financial administrations' that Firefly III supports.
107pub async fn list_user_groups(
108    configuration: &configuration::Configuration,
109    x_trace_id: Option<&str>,
110    limit: Option<i32>,
111    page: Option<i32>,
112) -> Result<models::UserGroupArray, Error<ListUserGroupsError>> {
113    let local_var_configuration = configuration;
114
115    let local_var_client = &local_var_configuration.client;
116
117    let local_var_uri_str = format!("{}/v1/user-groups", local_var_configuration.base_path);
118    let mut local_var_req_builder =
119        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
120
121    if let Some(ref local_var_str) = limit {
122        local_var_req_builder =
123            local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
124    }
125    if let Some(ref local_var_str) = page {
126        local_var_req_builder =
127            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
128    }
129    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
130        local_var_req_builder =
131            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
132    }
133    if let Some(local_var_param_value) = x_trace_id {
134        local_var_req_builder =
135            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
136    }
137    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
138        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
139    };
140    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
141        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
142    };
143
144    let local_var_req = local_var_req_builder.build()?;
145    let local_var_resp = local_var_client.execute(local_var_req).await?;
146
147    let local_var_status = local_var_resp.status();
148    let local_var_content = local_var_resp.text().await?;
149
150    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
151        serde_json::from_str(&local_var_content).map_err(Error::from)
152    } else {
153        let local_var_entity: Option<ListUserGroupsError> =
154            serde_json::from_str(&local_var_content).ok();
155        let local_var_error = ResponseContent {
156            status: local_var_status,
157            content: local_var_content,
158            entity: local_var_entity,
159        };
160        Err(Error::ResponseError(local_var_error))
161    }
162}
163
164/// Used to update a single user group. The available fields are still limited.
165pub async fn update_user_group(
166    configuration: &configuration::Configuration,
167    id: &str,
168    user_group_update: UserGroupUpdate,
169    x_trace_id: Option<&str>,
170) -> Result<models::UserGroupSingle, Error<UpdateUserGroupError>> {
171    let local_var_configuration = configuration;
172
173    let local_var_client = &local_var_configuration.client;
174
175    let local_var_uri_str = format!(
176        "{}/v1/user-groups/{id}",
177        local_var_configuration.base_path,
178        id = crate::apis::urlencode(id)
179    );
180    let mut local_var_req_builder =
181        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
182
183    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
184        local_var_req_builder =
185            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
186    }
187    if let Some(local_var_param_value) = x_trace_id {
188        local_var_req_builder =
189            local_var_req_builder.header("X-Trace-Id", local_var_param_value.to_string());
190    }
191    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
192        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
193    };
194    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
195        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
196    };
197    local_var_req_builder = local_var_req_builder.json(&user_group_update);
198
199    let local_var_req = local_var_req_builder.build()?;
200    let local_var_resp = local_var_client.execute(local_var_req).await?;
201
202    let local_var_status = local_var_resp.status();
203    let local_var_content = local_var_resp.text().await?;
204
205    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
206        serde_json::from_str(&local_var_content).map_err(Error::from)
207    } else {
208        let local_var_entity: Option<UpdateUserGroupError> =
209            serde_json::from_str(&local_var_content).ok();
210        let local_var_error = ResponseContent {
211            status: local_var_status,
212            content: local_var_content,
213            entity: local_var_entity,
214        };
215        Err(Error::ResponseError(local_var_error))
216    }
217}