/*
* Selling Partner API for Easy Ship
*
* Use the Selling Partner API for Easy Ship to build applications for sellers to manage and ship Amazon Easy Ship orders. With this API, you can get available time slots, schedule and reschedule Easy Ship orders, and print shipping labels, invoices, and warranties. To review the differences in Easy Ship operations by marketplace, refer to [Marketplace support](https://developer-docs.amazon.com/sp-api/docs/easyship-api-v2022-03-23-use-case-guide#marketplace-support).
*
* The version of the OpenAPI document: 2022-03-23
*
* 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 [`create_scheduled_package`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateScheduledPackageError {
Status400(models::easy_ship_2022_03_23::ErrorList),
Status401(models::easy_ship_2022_03_23::ErrorList),
Status403(models::easy_ship_2022_03_23::ErrorList),
Status404(models::easy_ship_2022_03_23::ErrorList),
Status413(models::easy_ship_2022_03_23::ErrorList),
Status415(models::easy_ship_2022_03_23::ErrorList),
Status429(models::easy_ship_2022_03_23::ErrorList),
Status500(models::easy_ship_2022_03_23::ErrorList),
Status503(models::easy_ship_2022_03_23::ErrorList),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`create_scheduled_package_bulk`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateScheduledPackageBulkError {
Status400(models::easy_ship_2022_03_23::ErrorList),
Status401(models::easy_ship_2022_03_23::ErrorList),
Status403(models::easy_ship_2022_03_23::ErrorList),
Status404(models::easy_ship_2022_03_23::ErrorList),
Status429(models::easy_ship_2022_03_23::ErrorList),
Status413(models::easy_ship_2022_03_23::ErrorList),
Status415(models::easy_ship_2022_03_23::ErrorList),
Status500(models::easy_ship_2022_03_23::ErrorList),
Status503(models::easy_ship_2022_03_23::ErrorList),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_scheduled_package`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetScheduledPackageError {
Status400(models::easy_ship_2022_03_23::ErrorList),
Status401(models::easy_ship_2022_03_23::ErrorList),
Status403(models::easy_ship_2022_03_23::ErrorList),
Status404(models::easy_ship_2022_03_23::ErrorList),
Status413(models::easy_ship_2022_03_23::ErrorList),
Status415(models::easy_ship_2022_03_23::ErrorList),
Status429(models::easy_ship_2022_03_23::ErrorList),
Status500(models::easy_ship_2022_03_23::ErrorList),
Status503(models::easy_ship_2022_03_23::ErrorList),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_handover_slots`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListHandoverSlotsError {
Status400(models::easy_ship_2022_03_23::ErrorList),
Status401(models::easy_ship_2022_03_23::ErrorList),
Status403(models::easy_ship_2022_03_23::ErrorList),
Status404(models::easy_ship_2022_03_23::ErrorList),
Status413(models::easy_ship_2022_03_23::ErrorList),
Status415(models::easy_ship_2022_03_23::ErrorList),
Status429(models::easy_ship_2022_03_23::ErrorList),
Status500(models::easy_ship_2022_03_23::ErrorList),
Status503(models::easy_ship_2022_03_23::ErrorList),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_scheduled_packages`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateScheduledPackagesError {
Status400(models::easy_ship_2022_03_23::ErrorList),
Status401(models::easy_ship_2022_03_23::ErrorList),
Status403(models::easy_ship_2022_03_23::ErrorList),
Status404(models::easy_ship_2022_03_23::ErrorList),
Status413(models::easy_ship_2022_03_23::ErrorList),
Status415(models::easy_ship_2022_03_23::ErrorList),
Status429(models::easy_ship_2022_03_23::ErrorList),
Status500(models::easy_ship_2022_03_23::ErrorList),
Status503(models::easy_ship_2022_03_23::ErrorList),
UnknownValue(serde_json::Value),
}
/// Schedules an Easy Ship order and returns the scheduled package information. This operation does the following: * Specifies the time slot and handover method for the order to be scheduled for delivery. * Updates the Easy Ship order status. * Generates a shipping label and an invoice. Calling `createScheduledPackage` also generates a warranty document if you specify a `SerialNumber` value. To get these documents, see [How to get invoice, shipping label, and warranty documents](doc:easyship-api-v2022-03-23-use-case-guide). * Shows the status of Easy Ship orders when you call the `getOrders` operation of the Selling Partner API for Orders and examine the `EasyShipShipmentStatus` property in the response body. See the **Shipping Label**, **Invoice**, and **Warranty** columns in the [Marketplace Support Table](doc:easyship-api-v2022-03-23-use-case-guide#marketplace-support-table) to see which documents are supported in each marketplace. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 | 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).
pub async fn create_scheduled_package(configuration: &configuration::Configuration, create_scheduled_package_request: models::easy_ship_2022_03_23::CreateScheduledPackageRequest) -> Result<models::easy_ship_2022_03_23::Package, Error<CreateScheduledPackageError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_create_scheduled_package_request = create_scheduled_package_request;
let uri_str = format!("{}/easyShip/2022-03-23/package", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_create_scheduled_package_request);
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::easy_ship_2022_03_23::Package`"))),
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::easy_ship_2022_03_23::Package`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateScheduledPackageError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// This operation automatically schedules a time slot for all the `amazonOrderId`s given as input, generating the associated shipping labels, along with other compliance documents according to the marketplace (refer to the [marketplace document support table](doc:easyship-api-v2022-03-23-use-case-guide#marketplace-support-table)). Developers calling this operation may optionally assign a `packageDetails` object, allowing them to input a preferred time slot for each order in their request. In this case, Amazon will try to schedule the respective packages using their optional settings. On the other hand, *i.e.*, if the time slot is not provided, Amazon will then pick the earliest time slot possible. Regarding the shipping label's file format, external developers are able to choose between PDF or ZPL, and Amazon will create the label accordingly. This operation returns an array composed of the scheduled packages, and a short-lived URL pointing to a zip file containing the generated shipping labels and the other documents enabled for your marketplace. If at least an order couldn't be scheduled, then Amazon adds the `rejectedOrders` list into the response, which contains an entry for each order we couldn't process. Each entry is composed of an error message describing the reason of the failure, so that sellers can take action. The table below displays the supported request and burst maximum rates: **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 | 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).
pub async fn create_scheduled_package_bulk(configuration: &configuration::Configuration, create_scheduled_packages_request: models::easy_ship_2022_03_23::CreateScheduledPackagesRequest) -> Result<models::easy_ship_2022_03_23::CreateScheduledPackagesResponse, Error<CreateScheduledPackageBulkError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_create_scheduled_packages_request = create_scheduled_packages_request;
let uri_str = format!("{}/easyShip/2022-03-23/packages/bulk", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_create_scheduled_packages_request);
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::easy_ship_2022_03_23::CreateScheduledPackagesResponse`"))),
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::easy_ship_2022_03_23::CreateScheduledPackagesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateScheduledPackageBulkError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns information about a package, including dimensions, weight, time slot information for handover, invoice and item information, and status. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 | 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).
pub async fn get_scheduled_package(configuration: &configuration::Configuration, amazon_order_id: &str, marketplace_id: &str) -> Result<models::easy_ship_2022_03_23::Package, Error<GetScheduledPackageError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_amazon_order_id = amazon_order_id;
let p_marketplace_id = marketplace_id;
let uri_str = format!("{}/easyShip/2022-03-23/package", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("amazonOrderId", &p_amazon_order_id.to_string())]);
req_builder = req_builder.query(&[("marketplaceId", &p_marketplace_id.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::easy_ship_2022_03_23::Package`"))),
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::easy_ship_2022_03_23::Package`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetScheduledPackageError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns time slots available for Easy Ship orders to be scheduled based on the package weight and dimensions that the seller specifies. This operation is available for scheduled and unscheduled orders based on marketplace support. See **Get Time Slots** in the [Marketplace Support Table](doc:easyship-api-v2022-03-23-use-case-guide#marketplace-support-table). This operation can return time slots that have either pickup or drop-off handover methods - see **Supported Handover Methods** in the [Marketplace Support Table](doc:easyship-api-v2022-03-23-use-case-guide#marketplace-support-table). **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 | 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).
pub async fn list_handover_slots(configuration: &configuration::Configuration, list_handover_slots_request: Option<models::easy_ship_2022_03_23::ListHandoverSlotsRequest>) -> Result<models::easy_ship_2022_03_23::ListHandoverSlotsResponse, Error<ListHandoverSlotsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_list_handover_slots_request = list_handover_slots_request;
let uri_str = format!("{}/easyShip/2022-03-23/timeSlot", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_list_handover_slots_request);
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::easy_ship_2022_03_23::ListHandoverSlotsResponse`"))),
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::easy_ship_2022_03_23::ListHandoverSlotsResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListHandoverSlotsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Updates the time slot for handing over the package indicated by the specified `scheduledPackageId`. You can get the new `slotId` value for the time slot by calling the `listHandoverSlots` operation before making another `patch` call. See the **Update Package** column in the [Marketplace Support Table](doc:easyship-api-v2022-03-23-use-case-guide#marketplace-support-table) to see which marketplaces this operation is supported in. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 | 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).
pub async fn update_scheduled_packages(configuration: &configuration::Configuration, update_scheduled_packages_request: Option<models::easy_ship_2022_03_23::UpdateScheduledPackagesRequest>) -> Result<models::easy_ship_2022_03_23::Packages, Error<UpdateScheduledPackagesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_update_scheduled_packages_request = update_scheduled_packages_request;
let uri_str = format!("{}/easyShip/2022-03-23/package", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&p_update_scheduled_packages_request);
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::easy_ship_2022_03_23::Packages`"))),
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::easy_ship_2022_03_23::Packages`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateScheduledPackagesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}