amazon_spapi/apis/
feeds_2021_06_30.rs

1/*
2 * Selling Partner API for Feeds
3 *
4 * The Selling Partner API for Feeds lets you upload data to Amazon on behalf of a selling partner.
5 *
6 * The version of the OpenAPI document: 2021-06-30
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`cancel_feed`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CancelFeedError {
20    Status400(models::feeds_2021_06_30::ErrorList),
21    Status401(models::feeds_2021_06_30::ErrorList),
22    Status403(models::feeds_2021_06_30::ErrorList),
23    Status404(models::feeds_2021_06_30::ErrorList),
24    Status415(models::feeds_2021_06_30::ErrorList),
25    Status429(models::feeds_2021_06_30::ErrorList),
26    Status500(models::feeds_2021_06_30::ErrorList),
27    Status503(models::feeds_2021_06_30::ErrorList),
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`create_feed`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum CreateFeedError {
35    Status400(models::feeds_2021_06_30::ErrorList),
36    Status401(models::feeds_2021_06_30::ErrorList),
37    Status403(models::feeds_2021_06_30::ErrorList),
38    Status404(models::feeds_2021_06_30::ErrorList),
39    Status415(models::feeds_2021_06_30::ErrorList),
40    Status429(models::feeds_2021_06_30::ErrorList),
41    Status500(models::feeds_2021_06_30::ErrorList),
42    Status503(models::feeds_2021_06_30::ErrorList),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`create_feed_document`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum CreateFeedDocumentError {
50    Status400(models::feeds_2021_06_30::ErrorList),
51    Status403(models::feeds_2021_06_30::ErrorList),
52    Status404(models::feeds_2021_06_30::ErrorList),
53    Status413(models::feeds_2021_06_30::ErrorList),
54    Status415(models::feeds_2021_06_30::ErrorList),
55    Status429(models::feeds_2021_06_30::ErrorList),
56    Status500(models::feeds_2021_06_30::ErrorList),
57    Status503(models::feeds_2021_06_30::ErrorList),
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`get_feed`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum GetFeedError {
65    Status400(models::feeds_2021_06_30::ErrorList),
66    Status401(models::feeds_2021_06_30::ErrorList),
67    Status403(models::feeds_2021_06_30::ErrorList),
68    Status404(models::feeds_2021_06_30::ErrorList),
69    Status415(models::feeds_2021_06_30::ErrorList),
70    Status429(models::feeds_2021_06_30::ErrorList),
71    Status500(models::feeds_2021_06_30::ErrorList),
72    Status503(models::feeds_2021_06_30::ErrorList),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`get_feed_document`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum GetFeedDocumentError {
80    Status400(models::feeds_2021_06_30::ErrorList),
81    Status401(models::feeds_2021_06_30::ErrorList),
82    Status403(models::feeds_2021_06_30::ErrorList),
83    Status404(models::feeds_2021_06_30::ErrorList),
84    Status415(models::feeds_2021_06_30::ErrorList),
85    Status429(models::feeds_2021_06_30::ErrorList),
86    Status500(models::feeds_2021_06_30::ErrorList),
87    Status503(models::feeds_2021_06_30::ErrorList),
88    UnknownValue(serde_json::Value),
89}
90
91/// struct for typed errors of method [`get_feeds`]
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(untagged)]
94pub enum GetFeedsError {
95    Status400(models::feeds_2021_06_30::ErrorList),
96    Status401(models::feeds_2021_06_30::ErrorList),
97    Status403(models::feeds_2021_06_30::ErrorList),
98    Status404(models::feeds_2021_06_30::ErrorList),
99    Status415(models::feeds_2021_06_30::ErrorList),
100    Status429(models::feeds_2021_06_30::ErrorList),
101    Status500(models::feeds_2021_06_30::ErrorList),
102    Status503(models::feeds_2021_06_30::ErrorList),
103    UnknownValue(serde_json::Value),
104}
105
106/// Cancels the feed that you specify. Only feeds with `processingStatus=IN_QUEUE` can be cancelled. Cancelled feeds are returned in subsequent calls to the [`getFeed`](https://developer-docs.amazon.com/sp-api/reference/getfeed) and [`getFeeds`](https://developer-docs.amazon.com/sp-api/reference/getfeeds) operations.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 15 |  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 indicates 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 in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
107pub async fn cancel_feed(
108    configuration: &configuration::Configuration,
109    feed_id: &str,
110) -> Result<(), Error<CancelFeedError>> {
111    // add a prefix to parameters to efficiently prevent name collisions
112    let p_feed_id = feed_id;
113
114    let uri_str = format!(
115        "{}/feeds/2021-06-30/feeds/{feedId}",
116        configuration.base_path,
117        feedId = crate::apis::urlencode(p_feed_id)
118    );
119    let mut req_builder = configuration
120        .client
121        .request(reqwest::Method::DELETE, &uri_str);
122
123    if let Some(ref user_agent) = configuration.user_agent {
124        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
125    }
126
127    let req = req_builder.build()?;
128    let resp = configuration.client.execute(req).await?;
129
130    let status = resp.status();
131
132    if !status.is_client_error() && !status.is_server_error() {
133        Ok(())
134    } else {
135        let content = resp.text().await?;
136        let entity: Option<CancelFeedError> = serde_json::from_str(&content).ok();
137        Err(Error::ResponseError(ResponseContent {
138            status,
139            content,
140            entity,
141        }))
142    }
143}
144
145/// Creates a feed. Upload the contents of the feed document before calling this operation.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.0083 | 15 |  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 indicates 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 in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).  The rate limit for the [`JSON_LISTINGS_FEED`](https://developer-docs.amazon.com/sp-api/docs/listings-feed-type-values#listings-feed) feed type differs from the rate limit for the [`createFeed`](https://developer-docs.amazon.com/sp-api/reference/createfeed) operation. For more information, refer to the [Building Listings Management Workflows Guide](https://developer-docs.amazon.com/sp-api/docs/building-listings-management-workflows-guide#should-i-submit-in-bulk-using-the-json_listings_feed-or-individually-with-the-listings-items-api).
146pub async fn create_feed(
147    configuration: &configuration::Configuration,
148    body: models::feeds_2021_06_30::CreateFeedSpecification,
149) -> Result<models::feeds_2021_06_30::CreateFeedResponse, Error<CreateFeedError>> {
150    // add a prefix to parameters to efficiently prevent name collisions
151    let p_body = body;
152
153    let uri_str = format!("{}/feeds/2021-06-30/feeds", configuration.base_path);
154    let mut req_builder = configuration
155        .client
156        .request(reqwest::Method::POST, &uri_str);
157
158    if let Some(ref user_agent) = configuration.user_agent {
159        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
160    }
161    req_builder = req_builder.json(&p_body);
162
163    let req = req_builder.build()?;
164    let resp = configuration.client.execute(req).await?;
165
166    let status = resp.status();
167    let content_type = resp
168        .headers()
169        .get("content-type")
170        .and_then(|v| v.to_str().ok())
171        .unwrap_or("application/octet-stream");
172    let content_type = super::ContentType::from(content_type);
173
174    if !status.is_client_error() && !status.is_server_error() {
175        let content = resp.text().await?;
176        match content_type {
177            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
178            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::CreateFeedResponse`"))),
179            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::feeds_2021_06_30::CreateFeedResponse`")))),
180        }
181    } else {
182        let content = resp.text().await?;
183        let entity: Option<CreateFeedError> = serde_json::from_str(&content).ok();
184        Err(Error::ResponseError(ResponseContent {
185            status,
186            content,
187            entity,
188        }))
189    }
190}
191
192/// Creates a feed document for the feed type that you specify. This operation returns a presigned URL for uploading the feed document contents. It also returns a `feedDocumentId` value that you can pass in with a subsequent call to the [`createFeed`](https://developer-docs.amazon.com/sp-api/reference/createfeed) operation.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.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 preceding table indicates 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 in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
193pub async fn create_feed_document(
194    configuration: &configuration::Configuration,
195    body: models::feeds_2021_06_30::CreateFeedDocumentSpecification,
196) -> Result<models::feeds_2021_06_30::CreateFeedDocumentResponse, Error<CreateFeedDocumentError>> {
197    // add a prefix to parameters to efficiently prevent name collisions
198    let p_body = body;
199
200    let uri_str = format!("{}/feeds/2021-06-30/documents", configuration.base_path);
201    let mut req_builder = configuration
202        .client
203        .request(reqwest::Method::POST, &uri_str);
204
205    if let Some(ref user_agent) = configuration.user_agent {
206        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
207    }
208    req_builder = req_builder.json(&p_body);
209
210    let req = req_builder.build()?;
211    let resp = configuration.client.execute(req).await?;
212
213    let status = resp.status();
214    let content_type = resp
215        .headers()
216        .get("content-type")
217        .and_then(|v| v.to_str().ok())
218        .unwrap_or("application/octet-stream");
219    let content_type = super::ContentType::from(content_type);
220
221    if !status.is_client_error() && !status.is_server_error() {
222        let content = resp.text().await?;
223        match content_type {
224            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
225            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::CreateFeedDocumentResponse`"))),
226            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::feeds_2021_06_30::CreateFeedDocumentResponse`")))),
227        }
228    } else {
229        let content = resp.text().await?;
230        let entity: Option<CreateFeedDocumentError> = serde_json::from_str(&content).ok();
231        Err(Error::ResponseError(ResponseContent {
232            status,
233            content,
234            entity,
235        }))
236    }
237}
238
239/// Returns feed details (including the `resultDocumentId`, if available) for the feed that you specify.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 2 | 15 |  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 indicates 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 in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
240pub async fn get_feed(
241    configuration: &configuration::Configuration,
242    feed_id: &str,
243) -> Result<models::feeds_2021_06_30::Feed, Error<GetFeedError>> {
244    // add a prefix to parameters to efficiently prevent name collisions
245    let p_feed_id = feed_id;
246
247    let uri_str = format!(
248        "{}/feeds/2021-06-30/feeds/{feedId}",
249        configuration.base_path,
250        feedId = crate::apis::urlencode(p_feed_id)
251    );
252    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
253
254    if let Some(ref user_agent) = configuration.user_agent {
255        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
256    }
257
258    let req = req_builder.build()?;
259    let resp = configuration.client.execute(req).await?;
260
261    let status = resp.status();
262    let content_type = resp
263        .headers()
264        .get("content-type")
265        .and_then(|v| v.to_str().ok())
266        .unwrap_or("application/octet-stream");
267    let content_type = super::ContentType::from(content_type);
268
269    if !status.is_client_error() && !status.is_server_error() {
270        let content = resp.text().await?;
271        match content_type {
272            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
273            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::Feed`"))),
274            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::feeds_2021_06_30::Feed`")))),
275        }
276    } else {
277        let content = resp.text().await?;
278        let entity: Option<GetFeedError> = serde_json::from_str(&content).ok();
279        Err(Error::ResponseError(ResponseContent {
280            status,
281            content,
282            entity,
283        }))
284    }
285}
286
287/// Returns the information required for retrieving a feed document's contents.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.0222 | 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 indicates 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 in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
288pub async fn get_feed_document(
289    configuration: &configuration::Configuration,
290    feed_document_id: &str,
291) -> Result<models::feeds_2021_06_30::FeedDocument, Error<GetFeedDocumentError>> {
292    // add a prefix to parameters to efficiently prevent name collisions
293    let p_feed_document_id = feed_document_id;
294
295    let uri_str = format!(
296        "{}/feeds/2021-06-30/documents/{feedDocumentId}",
297        configuration.base_path,
298        feedDocumentId = crate::apis::urlencode(p_feed_document_id)
299    );
300    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
301
302    if let Some(ref user_agent) = configuration.user_agent {
303        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
304    }
305
306    let req = req_builder.build()?;
307    let resp = configuration.client.execute(req).await?;
308
309    let status = resp.status();
310    let content_type = resp
311        .headers()
312        .get("content-type")
313        .and_then(|v| v.to_str().ok())
314        .unwrap_or("application/octet-stream");
315    let content_type = super::ContentType::from(content_type);
316
317    if !status.is_client_error() && !status.is_server_error() {
318        let content = resp.text().await?;
319        match content_type {
320            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
321            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::FeedDocument`"))),
322            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::feeds_2021_06_30::FeedDocument`")))),
323        }
324    } else {
325        let content = resp.text().await?;
326        let entity: Option<GetFeedDocumentError> = serde_json::from_str(&content).ok();
327        Err(Error::ResponseError(ResponseContent {
328            status,
329            content,
330            entity,
331        }))
332    }
333}
334
335/// Returns feed details for the feeds that match the filters that you specify.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 0.0222 | 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 indicates 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 in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
336pub async fn get_feeds(
337    configuration: &configuration::Configuration,
338    feed_types: Option<Vec<String>>,
339    marketplace_ids: Option<Vec<String>>,
340    page_size: Option<i32>,
341    processing_statuses: Option<Vec<String>>,
342    created_since: Option<String>,
343    created_until: Option<String>,
344    next_token: Option<&str>,
345) -> Result<models::feeds_2021_06_30::GetFeedsResponse, Error<GetFeedsError>> {
346    // add a prefix to parameters to efficiently prevent name collisions
347    let p_feed_types = feed_types;
348    let p_marketplace_ids = marketplace_ids;
349    let p_page_size = page_size;
350    let p_processing_statuses = processing_statuses;
351    let p_created_since = created_since;
352    let p_created_until = created_until;
353    let p_next_token = next_token;
354
355    let uri_str = format!("{}/feeds/2021-06-30/feeds", configuration.base_path);
356    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
357
358    if let Some(ref param_value) = p_feed_types {
359        req_builder = match "csv" {
360            "multi" => req_builder.query(
361                &param_value
362                    .into_iter()
363                    .map(|p| ("feedTypes".to_owned(), p.to_string()))
364                    .collect::<Vec<(std::string::String, std::string::String)>>(),
365            ),
366            _ => req_builder.query(&[(
367                "feedTypes",
368                &param_value
369                    .into_iter()
370                    .map(|p| p.to_string())
371                    .collect::<Vec<String>>()
372                    .join(",")
373                    .to_string(),
374            )]),
375        };
376    }
377    if let Some(ref param_value) = p_marketplace_ids {
378        req_builder = match "csv" {
379            "multi" => req_builder.query(
380                &param_value
381                    .into_iter()
382                    .map(|p| ("marketplaceIds".to_owned(), p.to_string()))
383                    .collect::<Vec<(std::string::String, std::string::String)>>(),
384            ),
385            _ => req_builder.query(&[(
386                "marketplaceIds",
387                &param_value
388                    .into_iter()
389                    .map(|p| p.to_string())
390                    .collect::<Vec<String>>()
391                    .join(",")
392                    .to_string(),
393            )]),
394        };
395    }
396    if let Some(ref param_value) = p_page_size {
397        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
398    }
399    if let Some(ref param_value) = p_processing_statuses {
400        req_builder = match "csv" {
401            "multi" => req_builder.query(
402                &param_value
403                    .into_iter()
404                    .map(|p| ("processingStatuses".to_owned(), p.to_string()))
405                    .collect::<Vec<(std::string::String, std::string::String)>>(),
406            ),
407            _ => req_builder.query(&[(
408                "processingStatuses",
409                &param_value
410                    .into_iter()
411                    .map(|p| p.to_string())
412                    .collect::<Vec<String>>()
413                    .join(",")
414                    .to_string(),
415            )]),
416        };
417    }
418    if let Some(ref param_value) = p_created_since {
419        req_builder = req_builder.query(&[("createdSince", &param_value.to_string())]);
420    }
421    if let Some(ref param_value) = p_created_until {
422        req_builder = req_builder.query(&[("createdUntil", &param_value.to_string())]);
423    }
424    if let Some(ref param_value) = p_next_token {
425        req_builder = req_builder.query(&[("nextToken", &param_value.to_string())]);
426    }
427    if let Some(ref user_agent) = configuration.user_agent {
428        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
429    }
430
431    let req = req_builder.build()?;
432    let resp = configuration.client.execute(req).await?;
433
434    let status = resp.status();
435    let content_type = resp
436        .headers()
437        .get("content-type")
438        .and_then(|v| v.to_str().ok())
439        .unwrap_or("application/octet-stream");
440    let content_type = super::ContentType::from(content_type);
441
442    if !status.is_client_error() && !status.is_server_error() {
443        let content = resp.text().await?;
444        match content_type {
445            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
446            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::feeds_2021_06_30::GetFeedsResponse`"))),
447            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::feeds_2021_06_30::GetFeedsResponse`")))),
448        }
449    } else {
450        let content = resp.text().await?;
451        let entity: Option<GetFeedsError> = serde_json::from_str(&content).ok();
452        Err(Error::ResponseError(ResponseContent {
453            status,
454            content,
455            entity,
456        }))
457    }
458}