amazon_spapi/apis/
catalog_items_v0.rs

1/*
2 * Selling Partner API for Catalog Items
3 *
4 * The Selling Partner API for Catalog Items helps you programmatically retrieve item details for items in the catalog.
5 *
6 * The version of the OpenAPI document: v0
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_catalog_categories`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListCatalogCategoriesError {
22    Status400(models::catalog_items_v0::ListCatalogCategoriesResponse),
23    Status401(models::catalog_items_v0::ListCatalogCategoriesResponse),
24    Status403(models::catalog_items_v0::ListCatalogCategoriesResponse),
25    Status404(models::catalog_items_v0::ListCatalogCategoriesResponse),
26    Status429(models::catalog_items_v0::ListCatalogCategoriesResponse),
27    Status500(models::catalog_items_v0::ListCatalogCategoriesResponse),
28    Status503(models::catalog_items_v0::ListCatalogCategoriesResponse),
29    UnknownValue(serde_json::Value),
30}
31
32
33/// Returns the parent categories to which an item belongs, based on the specified ASIN or SellerSKU.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 2 |  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).
34pub async fn list_catalog_categories(configuration: &configuration::Configuration, marketplace_id: &str, asin: Option<&str>, seller_sku: Option<&str>) -> Result<models::catalog_items_v0::ListCatalogCategoriesResponse, Error<ListCatalogCategoriesError>> {
35    // add a prefix to parameters to efficiently prevent name collisions
36    let p_marketplace_id = marketplace_id;
37    let p_asin = asin;
38    let p_seller_sku = seller_sku;
39
40    let uri_str = format!("{}/catalog/v0/categories", configuration.base_path);
41    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
42
43    req_builder = req_builder.query(&[("MarketplaceId", &p_marketplace_id.to_string())]);
44    if let Some(ref param_value) = p_asin {
45        req_builder = req_builder.query(&[("ASIN", &param_value.to_string())]);
46    }
47    if let Some(ref param_value) = p_seller_sku {
48        req_builder = req_builder.query(&[("SellerSKU", &param_value.to_string())]);
49    }
50    if let Some(ref user_agent) = configuration.user_agent {
51        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52    }
53
54    let req = req_builder.build()?;
55    let resp = configuration.client.execute(req).await?;
56
57    let status = resp.status();
58    let content_type = resp
59        .headers()
60        .get("content-type")
61        .and_then(|v| v.to_str().ok())
62        .unwrap_or("application/octet-stream");
63    let content_type = super::ContentType::from(content_type);
64
65    if !status.is_client_error() && !status.is_server_error() {
66        let content = resp.text().await?;
67        match content_type {
68            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::catalog_items_v0::ListCatalogCategoriesResponse`"))),
70            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::catalog_items_v0::ListCatalogCategoriesResponse`")))),
71        }
72    } else {
73        let content = resp.text().await?;
74        let entity: Option<ListCatalogCategoriesError> = serde_json::from_str(&content).ok();
75        Err(Error::ResponseError(ResponseContent { status, content, entity }))
76    }
77}
78