amazon_spapi/apis/
finances_v0.rs

1/*
2 * Selling Partner API for Finances
3 *
4 * The Selling Partner API for Finances helps you obtain financial information relevant to a seller's business. You can obtain financial events for a given order, financial event group, or date range without having to wait until a statement period closes. You can also obtain financial event groups for a given date range.
5 *
6 * The version of the OpenAPI document: v0
7 * 
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 [`list_financial_event_groups`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListFinancialEventGroupsError {
22    Status400(models::finances_v0::ListFinancialEventGroupsResponse),
23    Status403(models::finances_v0::ListFinancialEventGroupsResponse),
24    Status404(models::finances_v0::ListFinancialEventGroupsResponse),
25    Status429(models::finances_v0::ListFinancialEventGroupsResponse),
26    Status500(models::finances_v0::ListFinancialEventGroupsResponse),
27    Status503(models::finances_v0::ListFinancialEventGroupsResponse),
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`list_financial_events`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum ListFinancialEventsError {
35    Status400(models::finances_v0::ListFinancialEventsResponse),
36    Status403(models::finances_v0::ListFinancialEventsResponse),
37    Status404(models::finances_v0::ListFinancialEventsResponse),
38    Status429(models::finances_v0::ListFinancialEventsResponse),
39    Status500(models::finances_v0::ListFinancialEventsResponse),
40    Status503(models::finances_v0::ListFinancialEventsResponse),
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`list_financial_events_by_group_id`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum ListFinancialEventsByGroupIdError {
48    Status400(models::finances_v0::ListFinancialEventsResponse),
49    Status403(models::finances_v0::ListFinancialEventsResponse),
50    Status404(models::finances_v0::ListFinancialEventsResponse),
51    Status429(models::finances_v0::ListFinancialEventsResponse),
52    Status500(models::finances_v0::ListFinancialEventsResponse),
53    Status503(models::finances_v0::ListFinancialEventsResponse),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`list_financial_events_by_order_id`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum ListFinancialEventsByOrderIdError {
61    Status400(models::finances_v0::ListFinancialEventsResponse),
62    Status403(models::finances_v0::ListFinancialEventsResponse),
63    Status404(models::finances_v0::ListFinancialEventsResponse),
64    Status429(models::finances_v0::ListFinancialEventsResponse),
65    Status500(models::finances_v0::ListFinancialEventsResponse),
66    Status503(models::finances_v0::ListFinancialEventsResponse),
67    UnknownValue(serde_json::Value),
68}
69
70
71/// Returns financial event groups for a given date range. It may take up to 48 hours for orders to appear in your financial events.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.5 | 30 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
72pub async fn list_financial_event_groups(configuration: &configuration::Configuration, max_results_per_page: Option<i32>, financial_event_group_started_before: Option<String>, financial_event_group_started_after: Option<String>, next_token: Option<&str>) -> Result<models::finances_v0::ListFinancialEventGroupsResponse, Error<ListFinancialEventGroupsError>> {
73    // add a prefix to parameters to efficiently prevent name collisions
74    let p_max_results_per_page = max_results_per_page;
75    let p_financial_event_group_started_before = financial_event_group_started_before;
76    let p_financial_event_group_started_after = financial_event_group_started_after;
77    let p_next_token = next_token;
78
79    let uri_str = format!("{}/finances/v0/financialEventGroups", configuration.base_path);
80    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
81
82    if let Some(ref param_value) = p_max_results_per_page {
83        req_builder = req_builder.query(&[("MaxResultsPerPage", &param_value.to_string())]);
84    }
85    if let Some(ref param_value) = p_financial_event_group_started_before {
86        req_builder = req_builder.query(&[("FinancialEventGroupStartedBefore", &param_value.to_string())]);
87    }
88    if let Some(ref param_value) = p_financial_event_group_started_after {
89        req_builder = req_builder.query(&[("FinancialEventGroupStartedAfter", &param_value.to_string())]);
90    }
91    if let Some(ref param_value) = p_next_token {
92        req_builder = req_builder.query(&[("NextToken", &param_value.to_string())]);
93    }
94    if let Some(ref user_agent) = configuration.user_agent {
95        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
96    }
97
98    let req = req_builder.build()?;
99    let resp = configuration.client.execute(req).await?;
100
101    let status = resp.status();
102    let content_type = resp
103        .headers()
104        .get("content-type")
105        .and_then(|v| v.to_str().ok())
106        .unwrap_or("application/octet-stream");
107    let content_type = super::ContentType::from(content_type);
108
109    if !status.is_client_error() && !status.is_server_error() {
110        let content = resp.text().await?;
111        match content_type {
112            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::finances_v0::ListFinancialEventGroupsResponse`"))),
114            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::finances_v0::ListFinancialEventGroupsResponse`")))),
115        }
116    } else {
117        let content = resp.text().await?;
118        let entity: Option<ListFinancialEventGroupsError> = serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent { status, content, entity }))
120    }
121}
122
123/// Returns financial events for the specified data range. It may take up to 48 hours for orders to appear in your financial events. **Note:** in `ListFinancialEvents`, deferred events don't show up in responses until in they are released.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.5 | 30 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
124pub async fn list_financial_events(configuration: &configuration::Configuration, max_results_per_page: Option<i32>, posted_after: Option<String>, posted_before: Option<String>, next_token: Option<&str>) -> Result<models::finances_v0::ListFinancialEventsResponse, Error<ListFinancialEventsError>> {
125    // add a prefix to parameters to efficiently prevent name collisions
126    let p_max_results_per_page = max_results_per_page;
127    let p_posted_after = posted_after;
128    let p_posted_before = posted_before;
129    let p_next_token = next_token;
130
131    let uri_str = format!("{}/finances/v0/financialEvents", configuration.base_path);
132    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
133
134    if let Some(ref param_value) = p_max_results_per_page {
135        req_builder = req_builder.query(&[("MaxResultsPerPage", &param_value.to_string())]);
136    }
137    if let Some(ref param_value) = p_posted_after {
138        req_builder = req_builder.query(&[("PostedAfter", &param_value.to_string())]);
139    }
140    if let Some(ref param_value) = p_posted_before {
141        req_builder = req_builder.query(&[("PostedBefore", &param_value.to_string())]);
142    }
143    if let Some(ref param_value) = p_next_token {
144        req_builder = req_builder.query(&[("NextToken", &param_value.to_string())]);
145    }
146    if let Some(ref user_agent) = configuration.user_agent {
147        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
148    }
149
150    let req = req_builder.build()?;
151    let resp = configuration.client.execute(req).await?;
152
153    let status = resp.status();
154    let content_type = resp
155        .headers()
156        .get("content-type")
157        .and_then(|v| v.to_str().ok())
158        .unwrap_or("application/octet-stream");
159    let content_type = super::ContentType::from(content_type);
160
161    if !status.is_client_error() && !status.is_server_error() {
162        let content = resp.text().await?;
163        match content_type {
164            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
165            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::finances_v0::ListFinancialEventsResponse`"))),
166            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::finances_v0::ListFinancialEventsResponse`")))),
167        }
168    } else {
169        let content = resp.text().await?;
170        let entity: Option<ListFinancialEventsError> = serde_json::from_str(&content).ok();
171        Err(Error::ResponseError(ResponseContent { status, content, entity }))
172    }
173}
174
175/// Returns all financial events for the specified financial event group. It may take up to 48 hours for orders to appear in your financial events.  **Note:** This operation will only retrieve group's data for the past two years. If a request is submitted for data spanning more than two years, an empty response is returned.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.5 | 30 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
176pub async fn list_financial_events_by_group_id(configuration: &configuration::Configuration, event_group_id: &str, max_results_per_page: Option<i32>, posted_after: Option<String>, posted_before: Option<String>, next_token: Option<&str>) -> Result<models::finances_v0::ListFinancialEventsResponse, Error<ListFinancialEventsByGroupIdError>> {
177    // add a prefix to parameters to efficiently prevent name collisions
178    let p_event_group_id = event_group_id;
179    let p_max_results_per_page = max_results_per_page;
180    let p_posted_after = posted_after;
181    let p_posted_before = posted_before;
182    let p_next_token = next_token;
183
184    let uri_str = format!("{}/finances/v0/financialEventGroups/{eventGroupId}/financialEvents", configuration.base_path, eventGroupId=crate::apis::urlencode(p_event_group_id));
185    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
186
187    if let Some(ref param_value) = p_max_results_per_page {
188        req_builder = req_builder.query(&[("MaxResultsPerPage", &param_value.to_string())]);
189    }
190    if let Some(ref param_value) = p_posted_after {
191        req_builder = req_builder.query(&[("PostedAfter", &param_value.to_string())]);
192    }
193    if let Some(ref param_value) = p_posted_before {
194        req_builder = req_builder.query(&[("PostedBefore", &param_value.to_string())]);
195    }
196    if let Some(ref param_value) = p_next_token {
197        req_builder = req_builder.query(&[("NextToken", &param_value.to_string())]);
198    }
199    if let Some(ref user_agent) = configuration.user_agent {
200        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201    }
202
203    let req = req_builder.build()?;
204    let resp = configuration.client.execute(req).await?;
205
206    let status = resp.status();
207    let content_type = resp
208        .headers()
209        .get("content-type")
210        .and_then(|v| v.to_str().ok())
211        .unwrap_or("application/octet-stream");
212    let content_type = super::ContentType::from(content_type);
213
214    if !status.is_client_error() && !status.is_server_error() {
215        let content = resp.text().await?;
216        match content_type {
217            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
218            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::finances_v0::ListFinancialEventsResponse`"))),
219            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::finances_v0::ListFinancialEventsResponse`")))),
220        }
221    } else {
222        let content = resp.text().await?;
223        let entity: Option<ListFinancialEventsByGroupIdError> = serde_json::from_str(&content).ok();
224        Err(Error::ResponseError(ResponseContent { status, content, entity }))
225    }
226}
227
228/// Returns all financial events for the specified order. It may take up to 48 hours for orders to appear in your financial events.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.5 | 30 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
229pub async fn list_financial_events_by_order_id(configuration: &configuration::Configuration, order_id: &str, max_results_per_page: Option<i32>, next_token: Option<&str>) -> Result<models::finances_v0::ListFinancialEventsResponse, Error<ListFinancialEventsByOrderIdError>> {
230    // add a prefix to parameters to efficiently prevent name collisions
231    let p_order_id = order_id;
232    let p_max_results_per_page = max_results_per_page;
233    let p_next_token = next_token;
234
235    let uri_str = format!("{}/finances/v0/orders/{orderId}/financialEvents", configuration.base_path, orderId=crate::apis::urlencode(p_order_id));
236    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
237
238    if let Some(ref param_value) = p_max_results_per_page {
239        req_builder = req_builder.query(&[("MaxResultsPerPage", &param_value.to_string())]);
240    }
241    if let Some(ref param_value) = p_next_token {
242        req_builder = req_builder.query(&[("NextToken", &param_value.to_string())]);
243    }
244    if let Some(ref user_agent) = configuration.user_agent {
245        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
246    }
247
248    let req = req_builder.build()?;
249    let resp = configuration.client.execute(req).await?;
250
251    let status = resp.status();
252    let content_type = resp
253        .headers()
254        .get("content-type")
255        .and_then(|v| v.to_str().ok())
256        .unwrap_or("application/octet-stream");
257    let content_type = super::ContentType::from(content_type);
258
259    if !status.is_client_error() && !status.is_server_error() {
260        let content = resp.text().await?;
261        match content_type {
262            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
263            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::finances_v0::ListFinancialEventsResponse`"))),
264            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::finances_v0::ListFinancialEventsResponse`")))),
265        }
266    } else {
267        let content = resp.text().await?;
268        let entity: Option<ListFinancialEventsByOrderIdError> = serde_json::from_str(&content).ok();
269        Err(Error::ResponseError(ResponseContent { status, content, entity }))
270    }
271}
272