Skip to main content

amazon_spapi/apis/
listings_items_2020_09_01.rs

1/*
2 * Selling Partner API for Listings Items
3 *
4 * The Selling Partner API for Listings Items (Listings Items API) provides programmatic access to selling partner listings on Amazon. Use this API in collaboration with the Selling Partner API for Product Type Definitions, which you use to retrieve the information about Amazon product types needed to use the Listings Items API.  For more information, see the [Listing Items API Use Case Guide](doc:listings-items-api-v2020-09-01-use-case-guide).
5 *
6 * The version of the OpenAPI document: 2020-09-01
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 [`delete_listings_item`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteListingsItemError {
22    Status400(models::listings_items_2020_09_01::ErrorList),
23    Status403(models::listings_items_2020_09_01::ErrorList),
24    Status413(models::listings_items_2020_09_01::ErrorList),
25    Status415(models::listings_items_2020_09_01::ErrorList),
26    Status429(models::listings_items_2020_09_01::ErrorList),
27    Status500(models::listings_items_2020_09_01::ErrorList),
28    Status503(models::listings_items_2020_09_01::ErrorList),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`patch_listings_item`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PatchListingsItemError {
36    Status400(models::listings_items_2020_09_01::ErrorList),
37    Status403(models::listings_items_2020_09_01::ErrorList),
38    Status413(models::listings_items_2020_09_01::ErrorList),
39    Status415(models::listings_items_2020_09_01::ErrorList),
40    Status429(models::listings_items_2020_09_01::ErrorList),
41    Status500(models::listings_items_2020_09_01::ErrorList),
42    Status503(models::listings_items_2020_09_01::ErrorList),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`put_listings_item`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PutListingsItemError {
50    Status400(models::listings_items_2020_09_01::ErrorList),
51    Status403(models::listings_items_2020_09_01::ErrorList),
52    Status413(models::listings_items_2020_09_01::ErrorList),
53    Status415(models::listings_items_2020_09_01::ErrorList),
54    Status429(models::listings_items_2020_09_01::ErrorList),
55    Status500(models::listings_items_2020_09_01::ErrorList),
56    Status503(models::listings_items_2020_09_01::ErrorList),
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Delete a listings item for a selling partner.  **Note:** The parameters associated with this operation may contain special characters that must be encoded to successfully call the API. To avoid errors with SKUs when encoding URLs, refer to [URL Encoding](https://developer-docs.amazon.com/sp-api/docs/url-encoding).  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 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 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).
62pub async fn delete_listings_item(configuration: &configuration::Configuration, seller_id: &str, sku: &str, marketplace_ids: Vec<String>, issue_locale: Option<&str>) -> Result<models::listings_items_2020_09_01::ListingsItemSubmissionResponse, Error<DeleteListingsItemError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_seller_id = seller_id;
65    let p_sku = sku;
66    let p_marketplace_ids = marketplace_ids;
67    let p_issue_locale = issue_locale;
68
69    let uri_str = format!("{}/listings/2020-09-01/items/{sellerId}/{sku}", configuration.base_path, sellerId=crate::apis::urlencode(p_seller_id), sku=crate::apis::urlencode(p_sku));
70    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
71
72    req_builder = match "csv" {
73        "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)>>()),
74        _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
75    };
76    if let Some(ref param_value) = p_issue_locale {
77        req_builder = req_builder.query(&[("issueLocale", &param_value.to_string())]);
78    }
79    if let Some(ref user_agent) = configuration.user_agent {
80        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
81    }
82
83    let req = req_builder.build()?;
84    let resp = configuration.client.execute(req).await?;
85
86    let status = resp.status();
87    let content_type = resp
88        .headers()
89        .get("content-type")
90        .and_then(|v| v.to_str().ok())
91        .unwrap_or("application/octet-stream");
92    let content_type = super::ContentType::from(content_type);
93
94    if !status.is_client_error() && !status.is_server_error() {
95        let content = resp.text().await?;
96        match content_type {
97            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::listings_items_2020_09_01::ListingsItemSubmissionResponse`"))),
99            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::listings_items_2020_09_01::ListingsItemSubmissionResponse`")))),
100        }
101    } else {
102        let content = resp.text().await?;
103        let entity: Option<DeleteListingsItemError> = serde_json::from_str(&content).ok();
104        Err(Error::ResponseError(ResponseContent { status, content, entity }))
105    }
106}
107
108/// Partially update (patch) a listings item for a selling partner. Only top-level listings item attributes can be patched. Patching nested attributes is not supported.  **Note:** The parameters associated with this operation may contain special characters that must be encoded to successfully call the API. To avoid errors with SKUs when encoding URLs, refer to [URL Encoding](https://developer-docs.amazon.com/sp-api/docs/url-encoding).  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 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 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).
109pub async fn patch_listings_item(configuration: &configuration::Configuration, seller_id: &str, sku: &str, marketplace_ids: Vec<String>, body: models::listings_items_2020_09_01::ListingsItemPatchRequest, issue_locale: Option<&str>) -> Result<models::listings_items_2020_09_01::ListingsItemSubmissionResponse, Error<PatchListingsItemError>> {
110    // add a prefix to parameters to efficiently prevent name collisions
111    let p_seller_id = seller_id;
112    let p_sku = sku;
113    let p_marketplace_ids = marketplace_ids;
114    let p_body = body;
115    let p_issue_locale = issue_locale;
116
117    let uri_str = format!("{}/listings/2020-09-01/items/{sellerId}/{sku}", configuration.base_path, sellerId=crate::apis::urlencode(p_seller_id), sku=crate::apis::urlencode(p_sku));
118    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
119
120    req_builder = match "csv" {
121        "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)>>()),
122        _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
123    };
124    if let Some(ref param_value) = p_issue_locale {
125        req_builder = req_builder.query(&[("issueLocale", &param_value.to_string())]);
126    }
127    if let Some(ref user_agent) = configuration.user_agent {
128        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129    }
130    req_builder = req_builder.json(&p_body);
131
132    let req = req_builder.build()?;
133    let resp = configuration.client.execute(req).await?;
134
135    let status = resp.status();
136    let content_type = resp
137        .headers()
138        .get("content-type")
139        .and_then(|v| v.to_str().ok())
140        .unwrap_or("application/octet-stream");
141    let content_type = super::ContentType::from(content_type);
142
143    if !status.is_client_error() && !status.is_server_error() {
144        let content = resp.text().await?;
145        match content_type {
146            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
147            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::listings_items_2020_09_01::ListingsItemSubmissionResponse`"))),
148            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::listings_items_2020_09_01::ListingsItemSubmissionResponse`")))),
149        }
150    } else {
151        let content = resp.text().await?;
152        let entity: Option<PatchListingsItemError> = serde_json::from_str(&content).ok();
153        Err(Error::ResponseError(ResponseContent { status, content, entity }))
154    }
155}
156
157/// Creates a new or fully-updates an existing listings item for a selling partner.  **Note:** The parameters associated with this operation may contain special characters that must be encoded to successfully call the API. To avoid errors with SKUs when encoding URLs, refer to [URL Encoding](https://developer-docs.amazon.com/sp-api/docs/url-encoding).  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 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 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).
158pub async fn put_listings_item(configuration: &configuration::Configuration, seller_id: &str, sku: &str, marketplace_ids: Vec<String>, body: models::listings_items_2020_09_01::ListingsItemPutRequest, issue_locale: Option<&str>) -> Result<models::listings_items_2020_09_01::ListingsItemSubmissionResponse, Error<PutListingsItemError>> {
159    // add a prefix to parameters to efficiently prevent name collisions
160    let p_seller_id = seller_id;
161    let p_sku = sku;
162    let p_marketplace_ids = marketplace_ids;
163    let p_body = body;
164    let p_issue_locale = issue_locale;
165
166    let uri_str = format!("{}/listings/2020-09-01/items/{sellerId}/{sku}", configuration.base_path, sellerId=crate::apis::urlencode(p_seller_id), sku=crate::apis::urlencode(p_sku));
167    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
168
169    req_builder = match "csv" {
170        "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)>>()),
171        _ => req_builder.query(&[("marketplaceIds", &p_marketplace_ids.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
172    };
173    if let Some(ref param_value) = p_issue_locale {
174        req_builder = req_builder.query(&[("issueLocale", &param_value.to_string())]);
175    }
176    if let Some(ref user_agent) = configuration.user_agent {
177        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
178    }
179    req_builder = req_builder.json(&p_body);
180
181    let req = req_builder.build()?;
182    let resp = configuration.client.execute(req).await?;
183
184    let status = resp.status();
185    let content_type = resp
186        .headers()
187        .get("content-type")
188        .and_then(|v| v.to_str().ok())
189        .unwrap_or("application/octet-stream");
190    let content_type = super::ContentType::from(content_type);
191
192    if !status.is_client_error() && !status.is_server_error() {
193        let content = resp.text().await?;
194        match content_type {
195            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
196            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::listings_items_2020_09_01::ListingsItemSubmissionResponse`"))),
197            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::listings_items_2020_09_01::ListingsItemSubmissionResponse`")))),
198        }
199    } else {
200        let content = resp.text().await?;
201        let entity: Option<PutListingsItemError> = serde_json::from_str(&content).ok();
202        Err(Error::ResponseError(ResponseContent { status, content, entity }))
203    }
204}
205