amazon_spapi/apis/
replenishment_2022_11_07.rs

1/*
2 * Selling Partner API for Replenishment
3 *
4 * The Selling Partner API for Replenishment (Replenishment API) provides programmatic access to replenishment program metrics and offers. These programs provide recurring delivery of any replenishable item at a frequency chosen by the customer.  The Replenishment API is available worldwide wherever Amazon Subscribe & Save is available or is supported. The API is available to vendors and FBA selling partners.
5 *
6 * The version of the OpenAPI document: 2022-11-07
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/// struct for typed errors of method [`get_selling_partner_metrics`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum GetSellingPartnerMetricsError {
21    Status400(models::replenishment_2022_11_07::ErrorList),
22    Status401(models::replenishment_2022_11_07::ErrorList),
23    Status403(models::replenishment_2022_11_07::ErrorList),
24    Status404(models::replenishment_2022_11_07::ErrorList),
25    Status413(models::replenishment_2022_11_07::ErrorList),
26    Status415(models::replenishment_2022_11_07::ErrorList),
27    Status429(models::replenishment_2022_11_07::ErrorList),
28    Status500(models::replenishment_2022_11_07::ErrorList),
29    Status503(models::replenishment_2022_11_07::ErrorList),
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`list_offer_metrics`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum ListOfferMetricsError {
37    Status400(models::replenishment_2022_11_07::ErrorList),
38    Status401(models::replenishment_2022_11_07::ErrorList),
39    Status403(models::replenishment_2022_11_07::ErrorList),
40    Status404(models::replenishment_2022_11_07::ErrorList),
41    Status413(models::replenishment_2022_11_07::ErrorList),
42    Status415(models::replenishment_2022_11_07::ErrorList),
43    Status429(models::replenishment_2022_11_07::ErrorList),
44    Status500(models::replenishment_2022_11_07::ErrorList),
45    Status503(models::replenishment_2022_11_07::ErrorList),
46    UnknownValue(serde_json::Value),
47}
48
49/// struct for typed errors of method [`list_offers`]
50#[derive(Debug, Clone, Serialize, Deserialize)]
51#[serde(untagged)]
52pub enum ListOffersError {
53    Status400(models::replenishment_2022_11_07::ErrorList),
54    Status401(models::replenishment_2022_11_07::ErrorList),
55    Status403(models::replenishment_2022_11_07::ErrorList),
56    Status404(models::replenishment_2022_11_07::ErrorList),
57    Status413(models::replenishment_2022_11_07::ErrorList),
58    Status415(models::replenishment_2022_11_07::ErrorList),
59    Status429(models::replenishment_2022_11_07::ErrorList),
60    Status500(models::replenishment_2022_11_07::ErrorList),
61    Status503(models::replenishment_2022_11_07::ErrorList),
62    UnknownValue(serde_json::Value),
63}
64
65
66/// Returns aggregated replenishment program metrics for a selling partner.   **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 |  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).
67pub async fn get_selling_partner_metrics(configuration: &configuration::Configuration, body: Option<models::replenishment_2022_11_07::GetSellingPartnerMetricsRequest>) -> Result<models::replenishment_2022_11_07::GetSellingPartnerMetricsResponse, Error<GetSellingPartnerMetricsError>> {
68    // add a prefix to parameters to efficiently prevent name collisions
69    let p_body = body;
70
71    let uri_str = format!("{}/replenishment/2022-11-07/sellingPartners/metrics/search", configuration.base_path);
72    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
73
74    if let Some(ref user_agent) = configuration.user_agent {
75        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76    }
77    req_builder = req_builder.json(&p_body);
78
79    let req = req_builder.build()?;
80    let resp = configuration.client.execute(req).await?;
81
82    let status = resp.status();
83    let content_type = resp
84        .headers()
85        .get("content-type")
86        .and_then(|v| v.to_str().ok())
87        .unwrap_or("application/octet-stream");
88    let content_type = super::ContentType::from(content_type);
89
90    if !status.is_client_error() && !status.is_server_error() {
91        let content = resp.text().await?;
92        match content_type {
93            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
94            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::replenishment_2022_11_07::GetSellingPartnerMetricsResponse`"))),
95            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::replenishment_2022_11_07::GetSellingPartnerMetricsResponse`")))),
96        }
97    } else {
98        let content = resp.text().await?;
99        let entity: Option<GetSellingPartnerMetricsError> = serde_json::from_str(&content).ok();
100        Err(Error::ResponseError(ResponseContent { status, content, entity }))
101    }
102}
103
104/// Returns aggregated replenishment program metrics for a selling partner's offers.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 |  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).
105pub async fn list_offer_metrics(configuration: &configuration::Configuration, body: Option<models::replenishment_2022_11_07::ListOfferMetricsRequest>) -> Result<models::replenishment_2022_11_07::ListOfferMetricsResponse, Error<ListOfferMetricsError>> {
106    // add a prefix to parameters to efficiently prevent name collisions
107    let p_body = body;
108
109    let uri_str = format!("{}/replenishment/2022-11-07/offers/metrics/search", configuration.base_path);
110    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
111
112    if let Some(ref user_agent) = configuration.user_agent {
113        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114    }
115    req_builder = req_builder.json(&p_body);
116
117    let req = req_builder.build()?;
118    let resp = configuration.client.execute(req).await?;
119
120    let status = resp.status();
121    let content_type = resp
122        .headers()
123        .get("content-type")
124        .and_then(|v| v.to_str().ok())
125        .unwrap_or("application/octet-stream");
126    let content_type = super::ContentType::from(content_type);
127
128    if !status.is_client_error() && !status.is_server_error() {
129        let content = resp.text().await?;
130        match content_type {
131            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
132            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::replenishment_2022_11_07::ListOfferMetricsResponse`"))),
133            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::replenishment_2022_11_07::ListOfferMetricsResponse`")))),
134        }
135    } else {
136        let content = resp.text().await?;
137        let entity: Option<ListOfferMetricsError> = serde_json::from_str(&content).ok();
138        Err(Error::ResponseError(ResponseContent { status, content, entity }))
139    }
140}
141
142/// Returns the details of a selling partner's replenishment program offers.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 1 |  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).
143pub async fn list_offers(configuration: &configuration::Configuration, body: Option<models::replenishment_2022_11_07::ListOffersRequest>) -> Result<models::replenishment_2022_11_07::ListOffersResponse, Error<ListOffersError>> {
144    // add a prefix to parameters to efficiently prevent name collisions
145    let p_body = body;
146
147    let uri_str = format!("{}/replenishment/2022-11-07/offers/search", configuration.base_path);
148    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
149
150    if let Some(ref user_agent) = configuration.user_agent {
151        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
152    }
153    req_builder = req_builder.json(&p_body);
154
155    let req = req_builder.build()?;
156    let resp = configuration.client.execute(req).await?;
157
158    let status = resp.status();
159    let content_type = resp
160        .headers()
161        .get("content-type")
162        .and_then(|v| v.to_str().ok())
163        .unwrap_or("application/octet-stream");
164    let content_type = super::ContentType::from(content_type);
165
166    if !status.is_client_error() && !status.is_server_error() {
167        let content = resp.text().await?;
168        match content_type {
169            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
170            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::replenishment_2022_11_07::ListOffersResponse`"))),
171            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::replenishment_2022_11_07::ListOffersResponse`")))),
172        }
173    } else {
174        let content = resp.text().await?;
175        let entity: Option<ListOffersError> = serde_json::from_str(&content).ok();
176        Err(Error::ResponseError(ResponseContent { status, content, entity }))
177    }
178}
179