amazon_spapi/apis/
finances_2024_06_19.rs

1/*
2 * The 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 or date range without having to wait until a statement period closes.
5 *
6 * The version of the OpenAPI document: 2024-06-19
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_transactions`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListTransactionsError {
22    Status400(models::finances_2024_06_19::ErrorList),
23    Status403(models::finances_2024_06_19::ErrorList),
24    Status404(models::finances_2024_06_19::ErrorList),
25    Status415(models::finances_2024_06_19::ErrorList),
26    Status413(models::finances_2024_06_19::ErrorList),
27    Status429(models::finances_2024_06_19::ErrorList),
28    Status500(models::finances_2024_06_19::ErrorList),
29    Status503(models::finances_2024_06_19::ErrorList),
30    UnknownValue(serde_json::Value),
31}
32
33
34/// Returns transactions for the given parameters. Financial events might not include orders from the last 48 hours.  **Usage plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.5 | 10 |  The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may have higher rate and burst values than those shown here. For more information, refer to [Usage Plans and Rate Limits](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits).
35pub async fn list_transactions(configuration: &configuration::Configuration, posted_after: String, posted_before: Option<String>, marketplace_id: Option<&str>, transaction_status: Option<&str>, next_token: Option<&str>) -> Result<models::finances_2024_06_19::ListTransactionsResponse, Error<ListTransactionsError>> {
36    // add a prefix to parameters to efficiently prevent name collisions
37    let p_posted_after = posted_after;
38    let p_posted_before = posted_before;
39    let p_marketplace_id = marketplace_id;
40    let p_transaction_status = transaction_status;
41    let p_next_token = next_token;
42
43    let uri_str = format!("{}/finances/2024-06-19/transactions", configuration.base_path);
44    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
45
46    req_builder = req_builder.query(&[("postedAfter", &p_posted_after.to_string())]);
47    if let Some(ref param_value) = p_posted_before {
48        req_builder = req_builder.query(&[("postedBefore", &param_value.to_string())]);
49    }
50    if let Some(ref param_value) = p_marketplace_id {
51        req_builder = req_builder.query(&[("marketplaceId", &param_value.to_string())]);
52    }
53    if let Some(ref param_value) = p_transaction_status {
54        req_builder = req_builder.query(&[("transactionStatus", &param_value.to_string())]);
55    }
56    if let Some(ref param_value) = p_next_token {
57        req_builder = req_builder.query(&[("nextToken", &param_value.to_string())]);
58    }
59    if let Some(ref user_agent) = configuration.user_agent {
60        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61    }
62
63    let req = req_builder.build()?;
64    let resp = configuration.client.execute(req).await?;
65
66    let status = resp.status();
67    let content_type = resp
68        .headers()
69        .get("content-type")
70        .and_then(|v| v.to_str().ok())
71        .unwrap_or("application/octet-stream");
72    let content_type = super::ContentType::from(content_type);
73
74    if !status.is_client_error() && !status.is_server_error() {
75        let content = resp.text().await?;
76        match content_type {
77            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::finances_2024_06_19::ListTransactionsResponse`"))),
79            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_2024_06_19::ListTransactionsResponse`")))),
80        }
81    } else {
82        let content = resp.text().await?;
83        let entity: Option<ListTransactionsError> = serde_json::from_str(&content).ok();
84        Err(Error::ResponseError(ResponseContent { status, content, entity }))
85    }
86}
87