amazon_spapi/apis/
sales_v1.rs

1/*
2 * Selling Partner API for Sales
3 *
4 * The Selling Partner API for Sales provides APIs related to sales performance.
5 *
6 * The version of the OpenAPI document: v1
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 [`get_order_metrics`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetOrderMetricsError {
22    Status400(models::sales::GetOrderMetricsResponse),
23    Status403(models::sales::GetOrderMetricsResponse),
24    Status404(models::sales::GetOrderMetricsResponse),
25    Status413(models::sales::GetOrderMetricsResponse),
26    Status415(models::sales::GetOrderMetricsResponse),
27    Status429(models::sales::GetOrderMetricsResponse),
28    Status500(models::sales::GetOrderMetricsResponse),
29    Status503(models::sales::GetOrderMetricsResponse),
30    UnknownValue(serde_json::Value),
31}
32
33
34/// Returns aggregated order metrics for given interval, broken down by granularity, for given buyer type.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | .5 | 15 |  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](doc:usage-plans-and-rate-limits-in-the-sp-api).
35pub async fn get_order_metrics(configuration: &configuration::Configuration, marketplace_ids: Vec<String>, interval: &str, granularity: &str, granularity_time_zone: Option<&str>, buyer_type: Option<&str>, fulfillment_network: Option<&str>, first_day_of_week: Option<&str>, asin: Option<&str>, sku: Option<&str>, amazon_program: Option<&str>) -> Result<models::sales::GetOrderMetricsResponse, Error<GetOrderMetricsError>> {
36    // add a prefix to parameters to efficiently prevent name collisions
37    let p_marketplace_ids = marketplace_ids;
38    let p_interval = interval;
39    let p_granularity = granularity;
40    let p_granularity_time_zone = granularity_time_zone;
41    let p_buyer_type = buyer_type;
42    let p_fulfillment_network = fulfillment_network;
43    let p_first_day_of_week = first_day_of_week;
44    let p_asin = asin;
45    let p_sku = sku;
46    let p_amazon_program = amazon_program;
47
48    let uri_str = format!("{}/sales/v1/orderMetrics", configuration.base_path);
49    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
50
51    req_builder = match "csv" {
52        "multi" => req_builder.query(&p_marketplace_ids.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
53        _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
54    };
55    req_builder = req_builder.query(&[("interval", &p_interval.to_string())]);
56    if let Some(ref param_value) = p_granularity_time_zone {
57        req_builder = req_builder.query(&[("granularityTimeZone", &param_value.to_string())]);
58    }
59    req_builder = req_builder.query(&[("granularity", &p_granularity.to_string())]);
60    if let Some(ref param_value) = p_buyer_type {
61        req_builder = req_builder.query(&[("buyerType", &param_value.to_string())]);
62    }
63    if let Some(ref param_value) = p_fulfillment_network {
64        req_builder = req_builder.query(&[("fulfillmentNetwork", &param_value.to_string())]);
65    }
66    if let Some(ref param_value) = p_first_day_of_week {
67        req_builder = req_builder.query(&[("firstDayOfWeek", &param_value.to_string())]);
68    }
69    if let Some(ref param_value) = p_asin {
70        req_builder = req_builder.query(&[("asin", &param_value.to_string())]);
71    }
72    if let Some(ref param_value) = p_sku {
73        req_builder = req_builder.query(&[("sku", &param_value.to_string())]);
74    }
75    if let Some(ref param_value) = p_amazon_program {
76        req_builder = req_builder.query(&[("amazonProgram", &param_value.to_string())]);
77    }
78    if let Some(ref user_agent) = configuration.user_agent {
79        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
80    }
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86    let content_type = resp
87        .headers()
88        .get("content-type")
89        .and_then(|v| v.to_str().ok())
90        .unwrap_or("application/octet-stream");
91    let content_type = super::ContentType::from(content_type);
92
93    if !status.is_client_error() && !status.is_server_error() {
94        let content = resp.text().await?;
95        match content_type {
96            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::sales::GetOrderMetricsResponse`"))),
98            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::sales::GetOrderMetricsResponse`")))),
99        }
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<GetOrderMetricsError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent { status, content, entity }))
104    }
105}
106