/*
* Selling Partner API for FBA Inbound Eligibilty
*
* With the FBA Inbound Eligibility API, you can build applications that let sellers get eligibility previews for items before shipping them to Amazon's fulfillment centers. With this API you can find out if an item is eligible for inbound shipment to Amazon's fulfillment centers in a specific marketplace. You can also find out if an item is eligible for using the manufacturer barcode for FBA inventory tracking. Sellers can use this information to inform their decisions about which items to ship Amazon's fulfillment centers.
*
* The version of the OpenAPI document: v1
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`get_item_eligibility_preview`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetItemEligibilityPreviewError {
Status400(models::fba_inbound::GetItemEligibilityPreviewResponse),
Status401(models::fba_inbound::GetItemEligibilityPreviewResponse),
Status403(models::fba_inbound::GetItemEligibilityPreviewResponse),
Status404(models::fba_inbound::GetItemEligibilityPreviewResponse),
Status429(models::fba_inbound::GetItemEligibilityPreviewResponse),
Status500(models::fba_inbound::GetItemEligibilityPreviewResponse),
Status503(models::fba_inbound::GetItemEligibilityPreviewResponse),
UnknownValue(serde_json::Value),
}
/// This operation gets an eligibility preview for an item that you specify. You can specify the type of eligibility preview that you want (INBOUND or COMMINGLING). For INBOUND previews, you can specify the marketplace in which you want to determine the item's eligibility. **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).
pub async fn get_item_eligibility_preview(configuration: &configuration::Configuration, asin: &str, program: &str, marketplace_ids: Option<Vec<String>>) -> Result<models::fba_inbound::GetItemEligibilityPreviewResponse, Error<GetItemEligibilityPreviewError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_asin = asin;
let p_program = program;
let p_marketplace_ids = marketplace_ids;
let uri_str = format!("{}/fba/inbound/v1/eligibility/itemPreview", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_marketplace_ids {
req_builder = match "csv" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("marketplaceIds".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("marketplaceIds", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
req_builder = req_builder.query(&[("asin", &p_asin.to_string())]);
req_builder = req_builder.query(&[("program", &p_program.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::fba_inbound::GetItemEligibilityPreviewResponse`"))),
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::fba_inbound::GetItemEligibilityPreviewResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetItemEligibilityPreviewError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}