pub struct SpapiClient { /* private fields */ }Implementations§
Source§impl SpapiClient
impl SpapiClient
Sourcepub fn new(config: SpapiConfig) -> Result<Self>
pub fn new(config: SpapiConfig) -> Result<Self>
Create a new SP API client with the given configuration
Examples found in repository?
More examples
5async fn main() -> Result<()> {
6 let client = SpapiClient::new(SpapiConfig::from_env()?)?;
7
8 // let res = client
9 // .get_item_offers(client.get_marketplace_id(), "B0DGJC52FP", "New", None)
10 // .await?;
11 // println!("Item offers: {:?}", res);
12
13 let res = client
14 .get_item_offers_batch_by_asins(vec!["B0DGJC52FP", "B0BN72FYFG"])
15 .await?;
16 println!("Batch item offers: {:?}", res);
17
18 // let res = client
19 // .get_listing_offers_batch_by_skus(vec!["YOU_SKU1", "YOU_SKU2"])
20 // .await?;
21 // println!("Batch listing offers: {:?}", res);
22
23
24 Ok(())
25}6async fn main() -> Result<()> {
7 let spapi_config = SpapiConfig::from_env()?;
8 let spapi_client = SpapiClient::new(spapi_config.clone())?;
9 {
10 // Internally refresh the access token and create a configuration
11 // Configuration must be created for each API call
12 let configuration = spapi_client.create_configuration().await?;
13
14 // Wait for rate limit before making the API call
15 // When _guard is dropped, the rate limiter will mark the api call as having received a response
16 let _guard = spapi_client
17 .limiter()
18 .wait("get_marketplace_participations", 0.016, 15)
19 .await?;
20
21 // Call the API to get marketplace participations
22 let res = get_marketplace_participations(&configuration).await?;
23
24 println!("Marketplace Participations: {:#?}", res);
25 }
26 Ok(())
27}179async fn main() -> Result<()> {
180 env_logger::init();
181
182 let spapi_config = SpapiConfig::from_env()?;
183 let client = SpapiClient::new(spapi_config.clone())?;
184 let marketplace_ids = vec!["ATVPDKIKX0DER".to_string()]; // Amazon US Marketplace ID
185
186 // create report specification
187 let report_type = "GET_RESTOCK_INVENTORY_RECOMMENDATIONS_REPORT";
188 let report_content = client
189 .fetch_report(
190 report_type,
191 marketplace_ids.clone(),
192 None,
193 Some(|attempt, status| {
194 println!("Attempt get report {}: {:?}", attempt, status);
195 }),
196 )
197 .await?;
198
199 // save report content to a file
200 let report_file_path = "/tmp/restock_inventory_report.txt";
201 std::fs::write(report_file_path, &report_content)
202 .expect("Unable to write report content to file");
203
204 // // load report content from the file
205 // let report_file_path = "/tmp/restock_inventory_report.txt";
206 // let report_content =
207 // std::fs::read_to_string(report_file_path).expect("Unable to read report content from file");
208
209 let restocks = parse_restock_report(&report_content);
210
211 println!("Restock inventory report generated successfully.");
212 println!("{:#?}", restocks);
213
214 Ok(())
215}Sourcepub fn limiter(&self) -> &RateLimiter
pub fn limiter(&self) -> &RateLimiter
Examples found in repository?
6async fn main() -> Result<()> {
7 let spapi_config = SpapiConfig::from_env()?;
8 let spapi_client = SpapiClient::new(spapi_config.clone())?;
9 {
10 // Internally refresh the access token and create a configuration
11 // Configuration must be created for each API call
12 let configuration = spapi_client.create_configuration().await?;
13
14 // Wait for rate limit before making the API call
15 // When _guard is dropped, the rate limiter will mark the api call as having received a response
16 let _guard = spapi_client
17 .limiter()
18 .wait("get_marketplace_participations", 0.016, 15)
19 .await?;
20
21 // Call the API to get marketplace participations
22 let res = get_marketplace_participations(&configuration).await?;
23
24 println!("Marketplace Participations: {:#?}", res);
25 }
26 Ok(())
27}Sourcepub fn get_user_agent() -> String
pub fn get_user_agent() -> String
Get default user agent for the client
Sourcepub fn get_base_url(&self) -> String
pub fn get_base_url(&self) -> String
Get the base URL for the client
Sourcepub fn get_marketplace_id(&self) -> &str
pub fn get_marketplace_id(&self) -> &str
Get the region for the client
Examples found in repository?
7async fn get_inventory_summaries_all(
8 spapi: &SpapiClient,
9 details: Option<bool>,
10) -> Result<Vec<InventorySummary>> {
11 let mut res: Vec<InventorySummary> = Vec::new();
12 let mut next_token: Option<String> = None;
13
14 loop {
15 let granularity_type = "Marketplace";
16 let granularity_id = spapi.get_marketplace_id();
17 let marketplace_ids = vec![spapi.get_marketplace_id().to_string()];
18
19 let inventory = spapi
20 .get_inventory_summaries(
21 granularity_type,
22 granularity_id,
23 marketplace_ids,
24 details,
25 None,
26 None,
27 None,
28 next_token.as_deref(),
29 )
30 .await?;
31 log::debug!("Fetched inventory summaries successfully: {:?}", inventory);
32
33 if let Some(payload) = inventory.payload {
34 res.extend(payload.inventory_summaries);
35 }
36
37 if let Some(pagination) = inventory.pagination {
38 next_token = pagination.next_token;
39 } else {
40 break;
41 }
42 }
43
44 Ok(res)
45}Sourcepub async fn get_access_token(&self) -> Result<String>
pub async fn get_access_token(&self) -> Result<String>
Get access token from the auth client
Sourcepub fn is_sandbox(&self) -> bool
pub fn is_sandbox(&self) -> bool
Check if the client is in sandbox mode
Sourcepub async fn request(
&self,
endpoint: &ApiEndpoint,
query: Option<Vec<(String, String)>>,
header: Option<Vec<(&'static str, String)>>,
body: Option<&str>,
) -> Result<String>
pub async fn request( &self, endpoint: &ApiEndpoint, query: Option<Vec<(String, String)>>, header: Option<Vec<(&'static str, String)>>, body: Option<&str>, ) -> Result<String>
Make a request to the SP API
Sourcepub async fn upload(
&self,
url: &str,
content: &str,
content_type: &str,
) -> Result<()>
pub async fn upload( &self, url: &str, content: &str, content_type: &str, ) -> Result<()>
Upload content to the feed document URL (direct S3 upload)
Sourcepub async fn download(&self, url: &str) -> Result<String>
pub async fn download(&self, url: &str) -> Result<String>
Download content from a feed document URL
Sourcepub async fn get_rate_limit_status(
&self,
) -> Result<HashMap<String, (f64, f64, u32)>>
pub async fn get_rate_limit_status( &self, ) -> Result<HashMap<String, (f64, f64, u32)>>
Check if rate limiting is enabled and get token status
Sourcepub async fn check_rate_limit_availability(
&self,
endpoint_id: &String,
) -> Result<bool>
pub async fn check_rate_limit_availability( &self, endpoint_id: &String, ) -> Result<bool>
Check if a token is available for a specific endpoint without consuming it
Sourcepub async fn refresh_access_token_if_needed(&self) -> Result<()>
pub async fn refresh_access_token_if_needed(&self) -> Result<()>
Refresh the access token if needed
Sourcepub async fn force_refresh_token(&self) -> Result<()>
pub async fn force_refresh_token(&self) -> Result<()>
Force refresh the access token
Sourcepub fn get_http_client(&self) -> &Client
pub fn get_http_client(&self) -> &Client
Get access to the underlying HTTP client for direct requests
Sourcepub async fn create_configuration(&self) -> Result<Configuration>
pub async fn create_configuration(&self) -> Result<Configuration>
Create a new configuration for the generated APIs This function refreshes the access token and sets up the configuration
Examples found in repository?
6async fn main() -> Result<()> {
7 let spapi_config = SpapiConfig::from_env()?;
8 let spapi_client = SpapiClient::new(spapi_config.clone())?;
9 {
10 // Internally refresh the access token and create a configuration
11 // Configuration must be created for each API call
12 let configuration = spapi_client.create_configuration().await?;
13
14 // Wait for rate limit before making the API call
15 // When _guard is dropped, the rate limiter will mark the api call as having received a response
16 let _guard = spapi_client
17 .limiter()
18 .wait("get_marketplace_participations", 0.016, 15)
19 .await?;
20
21 // Call the API to get marketplace participations
22 let res = get_marketplace_participations(&configuration).await?;
23
24 println!("Marketplace Participations: {:#?}", res);
25 }
26 Ok(())
27}pub fn from_json<'a, T>(s: &'a str) -> Result<T>where
T: Deserialize<'a>,
Source§impl SpapiClient
impl SpapiClient
Sourcepub async fn search_catalog_items(
&self,
marketplace_ids: Vec<String>,
identifiers: Option<Vec<String>>,
identifiers_type: Option<&str>,
included_data: Option<Vec<String>>,
locale: Option<&str>,
seller_id: Option<&str>,
keywords: Option<Vec<String>>,
brand_names: Option<Vec<String>>,
classification_ids: Option<Vec<String>>,
page_size: Option<i32>,
page_token: Option<&str>,
keywords_locale: Option<&str>,
) -> Result<ItemSearchResults>
pub async fn search_catalog_items( &self, marketplace_ids: Vec<String>, identifiers: Option<Vec<String>>, identifiers_type: Option<&str>, included_data: Option<Vec<String>>, locale: Option<&str>, seller_id: Option<&str>, keywords: Option<Vec<String>>, brand_names: Option<Vec<String>>, classification_ids: Option<Vec<String>>, page_size: Option<i32>, page_token: Option<&str>, keywords_locale: Option<&str>, ) -> Result<ItemSearchResults>
Search for a list of Amazon catalog items and item-related information. You can search by identifier or by keywords. Usage Plan: | Rate (requests per second) | Burst | | –– | –– | | 2 | 2 | The x-amzn-RateLimit-Limit response header contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to Usage Plans and Rate Limits.
Sourcepub async fn get_catalog_item(
&self,
asin: &str,
marketplace_ids: Vec<String>,
included_data: Option<Vec<String>>,
locale: Option<&str>,
) -> Result<Item>
pub async fn get_catalog_item( &self, asin: &str, marketplace_ids: Vec<String>, included_data: Option<Vec<String>>, locale: Option<&str>, ) -> Result<Item>
Retrieves details for an item in the Amazon catalog. Usage Plan: | Rate (requests per second) | Burst | | –– | –– | | 2 | 2 | The x-amzn-RateLimit-Limit response header contains the usage plan rate limits for the operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to Usage Plans and Rate Limits.
Sourcepub async fn search_catalog_items_by_asin(
&self,
asin: &str,
marketplace_ids: Vec<String>,
included_data: Option<Vec<String>>,
locale: Option<&str>,
) -> Result<ItemSearchResults>
pub async fn search_catalog_items_by_asin( &self, asin: &str, marketplace_ids: Vec<String>, included_data: Option<Vec<String>>, locale: Option<&str>, ) -> Result<ItemSearchResults>
Convenience method to search for items by ASIN.
Sourcepub async fn search_catalog_items_by_keywords(
&self,
keywords: Vec<String>,
marketplace_ids: Vec<String>,
included_data: Option<Vec<String>>,
brand_names: Option<Vec<String>>,
classification_ids: Option<Vec<String>>,
page_size: Option<i32>,
page_token: Option<&str>,
keywords_locale: Option<&str>,
) -> Result<ItemSearchResults>
pub async fn search_catalog_items_by_keywords( &self, keywords: Vec<String>, marketplace_ids: Vec<String>, included_data: Option<Vec<String>>, brand_names: Option<Vec<String>>, classification_ids: Option<Vec<String>>, page_size: Option<i32>, page_token: Option<&str>, keywords_locale: Option<&str>, ) -> Result<ItemSearchResults>
Convenience method to search for items by keywords.
Source§impl SpapiClient
impl SpapiClient
pub async fn add_inventory( &self, x_amzn_idempotency_token: &str, add_inventory_request_body: AddInventoryRequest, ) -> Result<AddInventoryResponse>
pub async fn create_inventory_item( &self, create_inventory_item_request_body: CreateInventoryItemRequest, ) -> Result<CreateInventoryItemResponse>
pub async fn delete_inventory_item( &self, seller_sku: &str, marketplace_id: &str, ) -> Result<DeleteInventoryItemResponse>
Sourcepub async fn get_inventory_summaries(
&self,
granularity_type: &str,
granularity_id: &str,
marketplace_ids: Vec<String>,
details: Option<bool>,
start_date_time: Option<String>,
seller_skus: Option<Vec<String>>,
seller_sku: Option<&str>,
next_token: Option<&str>,
) -> Result<GetInventorySummariesResponse>
pub async fn get_inventory_summaries( &self, granularity_type: &str, granularity_id: &str, marketplace_ids: Vec<String>, details: Option<bool>, start_date_time: Option<String>, seller_skus: Option<Vec<String>>, seller_sku: Option<&str>, next_token: Option<&str>, ) -> Result<GetInventorySummariesResponse>
Get inventory summaries for FBA inventory
Returns a list of inventory summaries. The summaries returned depend on the presence of the startDateTime and sellerSkus parameters.
Examples found in repository?
7async fn get_inventory_summaries_all(
8 spapi: &SpapiClient,
9 details: Option<bool>,
10) -> Result<Vec<InventorySummary>> {
11 let mut res: Vec<InventorySummary> = Vec::new();
12 let mut next_token: Option<String> = None;
13
14 loop {
15 let granularity_type = "Marketplace";
16 let granularity_id = spapi.get_marketplace_id();
17 let marketplace_ids = vec![spapi.get_marketplace_id().to_string()];
18
19 let inventory = spapi
20 .get_inventory_summaries(
21 granularity_type,
22 granularity_id,
23 marketplace_ids,
24 details,
25 None,
26 None,
27 None,
28 next_token.as_deref(),
29 )
30 .await?;
31 log::debug!("Fetched inventory summaries successfully: {:?}", inventory);
32
33 if let Some(payload) = inventory.payload {
34 res.extend(payload.inventory_summaries);
35 }
36
37 if let Some(pagination) = inventory.pagination {
38 next_token = pagination.next_token;
39 } else {
40 break;
41 }
42 }
43
44 Ok(res)
45}Source§impl SpapiClient
impl SpapiClient
Source§impl SpapiClient
impl SpapiClient
pub async fn list_financial_event_groups( &self, max_results_per_page: Option<i32>, financial_event_group_started_before: Option<String>, financial_event_group_started_after: Option<String>, next_token: Option<&str>, ) -> Result<ListFinancialEventGroupsResponse>
Sourcepub async fn list_financial_events(
&self,
max_results_per_page: Option<i32>,
posted_after: Option<String>,
posted_before: Option<String>,
next_token: Option<&str>,
) -> Result<ListFinancialEventsResponse>
pub async fn list_financial_events( &self, max_results_per_page: Option<i32>, posted_after: Option<String>, posted_before: Option<String>, next_token: Option<&str>, ) -> Result<ListFinancialEventsResponse>
max_results_per_page: 1 to 100 default to 100
pub async fn list_financial_events_by_group_id( &self, event_group_id: &str, max_results_per_page: Option<i32>, posted_after: Option<String>, posted_before: Option<String>, next_token: Option<&str>, ) -> Result<ListFinancialEventsResponse>
pub async fn list_financial_events_by_order_id( &self, order_id: &str, max_results_per_page: Option<i32>, next_token: Option<&str>, ) -> Result<ListFinancialEventsResponse>
Source§impl SpapiClient
impl SpapiClient
Sourcepub async fn cancel_feed(&self, feed_id: &str) -> Result<()>
pub async fn cancel_feed(&self, feed_id: &str) -> Result<()>
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 and 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.
Sourcepub async fn create_feed(
&self,
body: CreateFeedSpecification,
) -> Result<CreateFeedResponse>
pub async fn create_feed( &self, body: CreateFeedSpecification, ) -> Result<CreateFeedResponse>
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. The rate limit for the JSON_LISTINGS_FEED feed type differs from the rate limit for the createFeed operation. For more information, refer to the Building Listings Management Workflows Guide.
Sourcepub async fn create_feed_document(
&self,
body: CreateFeedDocumentSpecification,
) -> Result<CreateFeedDocumentResponse>
pub async fn create_feed_document( &self, body: CreateFeedDocumentSpecification, ) -> Result<CreateFeedDocumentResponse>
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 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.
Sourcepub async fn get_feed(&self, feed_id: &str) -> Result<Feed>
pub async fn get_feed(&self, feed_id: &str) -> Result<Feed>
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.
Sourcepub async fn get_feed_document(
&self,
feed_document_id: &str,
) -> Result<FeedDocument>
pub async fn get_feed_document( &self, feed_document_id: &str, ) -> Result<FeedDocument>
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.
Sourcepub async fn get_feeds(
&self,
feed_types: Option<Vec<String>>,
marketplace_ids: Option<Vec<String>>,
page_size: Option<i32>,
processing_statuses: Option<Vec<String>>,
created_since: Option<String>,
created_until: Option<String>,
next_token: Option<&str>,
) -> Result<GetFeedsResponse>
pub async fn get_feeds( &self, feed_types: Option<Vec<String>>, marketplace_ids: Option<Vec<String>>, page_size: Option<i32>, processing_statuses: Option<Vec<String>>, created_since: Option<String>, created_until: Option<String>, next_token: Option<&str>, ) -> Result<GetFeedsResponse>
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.
Source§impl SpapiClient
impl SpapiClient
Sourcepub async fn delete_listings_item(
&self,
seller_id: &str,
sku: &str,
marketplace_ids: Vec<String>,
issue_locale: Option<&str>,
) -> Result<ListingsItemSubmissionResponse>
pub async fn delete_listings_item( &self, seller_id: &str, sku: &str, marketplace_ids: Vec<String>, issue_locale: Option<&str>, ) -> Result<ListingsItemSubmissionResponse>
Delete a listings item for a selling partner. Usage Plan: | Rate (requests per second) | Burst | | –– | –– | | 5 | 5 | 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 can receive higher rate and burst values than those shown here. For more information, refer to Usage Plans and Rate Limits in the Selling Partner API documentation.
Sourcepub async fn get_listings_item(
&self,
seller_id: &str,
sku: &str,
marketplace_ids: Vec<String>,
issue_locale: Option<&str>,
included_data: Option<Vec<String>>,
) -> Result<Item>
pub async fn get_listings_item( &self, seller_id: &str, sku: &str, marketplace_ids: Vec<String>, issue_locale: Option<&str>, included_data: Option<Vec<String>>, ) -> Result<Item>
Returns details about a listings item for a selling partner. 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 preceding table indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput can receive higher rate and burst values than those shown here. For more information, refer to Usage Plans and Rate Limits in the Selling Partner API documentation.
Examples found in repository?
110async fn get_current_listing(
111 client: &SpapiClient,
112 seller_id: &str,
113 sku: &str,
114 marketplace_ids: &[String],
115) -> Result<amazon_spapi::models::listings_items_2021_08_01::Item> {
116 client
117 .get_listings_item(
118 seller_id,
119 sku,
120 marketplace_ids.to_vec(),
121 None, // issue_locale
122 Some(vec!["summaries".to_string(), "attributes".to_string()]), // included_data
123 )
124 .await
125}Sourcepub async fn patch_listings_item(
&self,
seller_id: &str,
sku: &str,
marketplace_ids: Vec<String>,
body: ListingsItemPatchRequest,
included_data: Option<Vec<String>>,
mode: Option<&str>,
issue_locale: Option<&str>,
) -> Result<ListingsItemSubmissionResponse>
pub async fn patch_listings_item( &self, seller_id: &str, sku: &str, marketplace_ids: Vec<String>, body: ListingsItemPatchRequest, included_data: Option<Vec<String>>, mode: Option<&str>, issue_locale: Option<&str>, ) -> Result<ListingsItemSubmissionResponse>
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. Usage Plan: | Rate (requests per second) | Burst | | –– | –– | | 5 | 5 | 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 can receive higher rate and burst values than those shown here. For more information, refer to Usage Plans and Rate Limits in the Selling Partner API documentation.
Examples found in repository?
52async fn update_listing_price(
53 client: &SpapiClient,
54 seller_id: &str,
55 sku: &str,
56 marketplace_ids: &[String],
57 new_price: f64,
58) -> Result<amazon_spapi::models::listings_items_2021_08_01::ListingsItemSubmissionResponse> {
59 let mut purchasable_offer = HashMap::new();
60 purchasable_offer.insert("audience".to_string(), json!("ALL"));
61 purchasable_offer.insert("currency".to_string(), json!("USD"));
62 purchasable_offer.insert("marketplace_id".to_string(), json!(marketplace_ids[0]));
63 purchasable_offer.insert(
64 "our_price".to_string(),
65 json!([{
66 "schedule": [{
67 "value_with_tax": new_price
68 }]
69 }]),
70 );
71
72 let mut list_price = HashMap::new();
73 list_price.insert("marketplace_id".to_string(), json!(marketplace_ids[0]));
74 list_price.insert("currency".to_string(), json!("USD"));
75 list_price.insert("value".to_string(), json!(new_price));
76
77 let purchasable_offer_patch = PatchOperation {
78 op: Op::Replace,
79 path: "/attributes/purchasable_offer".to_string(),
80 value: Some(vec![purchasable_offer]),
81 };
82
83 let list_price_patch = PatchOperation {
84 op: Op::Replace,
85 path: "/attributes/list_price".to_string(),
86 value: Some(vec![list_price]),
87 };
88
89 let patch_request = ListingsItemPatchRequest {
90 product_type: "PRODUCT".to_string(),
91 patches: vec![purchasable_offer_patch, list_price_patch],
92 };
93
94 println!("{:#?}", patch_request);
95
96 client
97 .patch_listings_item(
98 seller_id,
99 sku,
100 marketplace_ids.to_vec(),
101 patch_request,
102 None, // included_data
103 None, // Some("VALIDATION_PREVIEW"), // mode - Can use "VALIDATION_PREVIEW" to validate first
104 None, // issue_locale
105 )
106 .await
107}Sourcepub async fn put_listings_item(
&self,
seller_id: &str,
sku: &str,
marketplace_ids: Vec<String>,
body: ListingsItemPutRequest,
included_data: Option<Vec<String>>,
mode: Option<&str>,
issue_locale: Option<&str>,
) -> Result<ListingsItemSubmissionResponse>
pub async fn put_listings_item( &self, seller_id: &str, sku: &str, marketplace_ids: Vec<String>, body: ListingsItemPutRequest, included_data: Option<Vec<String>>, mode: Option<&str>, issue_locale: Option<&str>, ) -> Result<ListingsItemSubmissionResponse>
Creates a new or fully-updates an existing listings item for a selling partner. 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 preceding table indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput can receive higher rate and burst values than those shown here. For more information, refer to Usage Plans and Rate Limits in the Selling Partner API documentation.
Sourcepub async fn search_listings_items(
&self,
seller_id: &str,
marketplace_ids: Vec<String>,
issue_locale: Option<&str>,
included_data: Option<Vec<String>>,
identifiers: Option<Vec<String>>,
identifiers_type: Option<&str>,
variation_parent_sku: Option<&str>,
package_hierarchy_sku: Option<&str>,
created_after: Option<String>,
created_before: Option<String>,
last_updated_after: Option<String>,
last_updated_before: Option<String>,
with_issue_severity: Option<Vec<String>>,
with_status: Option<Vec<String>>,
without_status: Option<Vec<String>>,
sort_by: Option<&str>,
sort_order: Option<&str>,
page_size: Option<i32>,
page_token: Option<&str>,
) -> Result<ItemSearchResults>
pub async fn search_listings_items( &self, seller_id: &str, marketplace_ids: Vec<String>, issue_locale: Option<&str>, included_data: Option<Vec<String>>, identifiers: Option<Vec<String>>, identifiers_type: Option<&str>, variation_parent_sku: Option<&str>, package_hierarchy_sku: Option<&str>, created_after: Option<String>, created_before: Option<String>, last_updated_after: Option<String>, last_updated_before: Option<String>, with_issue_severity: Option<Vec<String>>, with_status: Option<Vec<String>>, without_status: Option<Vec<String>>, sort_by: Option<&str>, sort_order: Option<&str>, page_size: Option<i32>, page_token: Option<&str>, ) -> Result<ItemSearchResults>
Search for and return a list of selling partner listings items and their respective details. Usage Plan: | Rate (requests per second) | Burst | | –– | –– | | 5 | 5 | The x-amzn-RateLimit-Limit response header returns the usage plan rate limits that are applied to the requested operation, when available. The preceding table contains the default rate and burst values for this operation. Selling partners whose business demands require higher throughput might have higher rate and burst values than those shown here. For more information, refer to Usage Plans and Rate Limits.
Source§impl SpapiClient
impl SpapiClient
Sourcepub async fn get_pricing(
&self,
marketplace_id: &str,
item_type: &str,
asins: Option<Vec<String>>,
skus: Option<Vec<String>>,
item_condition: Option<String>,
offer_type: Option<String>,
) -> Result<GetPricingResponse>
pub async fn get_pricing( &self, marketplace_id: &str, item_type: &str, asins: Option<Vec<String>>, skus: Option<Vec<String>>, item_condition: Option<String>, offer_type: Option<String>, ) -> Result<GetPricingResponse>
Returns pricing information for a seller’s offer listings based on seller SKU or ASIN.
§Arguments
marketplace_id- A marketplace identifier. Specifies the marketplace for which prices are returned.item_type- Indicates whether ASIN values or seller SKU values are used to identify items. Possible values: “Asin”, “Sku”.asins- A list of up to twenty Amazon Standard Identification Number (ASIN) values used to identify items in the given marketplace.skus- A list of up to twenty seller SKU values used to identify items in the given marketplace.item_condition- Filters the offer listings based on item condition. Possible values: “New”, “Used”, “Collectible”, “Refurbished”, “Club”.offer_type- Indicates whether to request pricing information for the seller’s B2C or B2B offers. Default is “B2C”.
§Rate Limits
- Rate: 0.5 requests per second
- Burst: 1
§Examples
let response = client.get_pricing(
"ATVPDKIKX0DER",
"Asin",
Some(vec!["B08N5WRWNW".to_string(), "B07XJ8C8F7".to_string()]),
None,
Some("New".to_string()),
Some("B2C".to_string()),
).await?;
println!("Pricing information: {:?}", response);Sourcepub async fn get_competitive_pricing(
&self,
marketplace_id: &str,
item_type: &str,
asins: Option<Vec<String>>,
skus: Option<Vec<String>>,
customer_type: Option<String>,
) -> Result<GetPricingResponse>
pub async fn get_competitive_pricing( &self, marketplace_id: &str, item_type: &str, asins: Option<Vec<String>>, skus: Option<Vec<String>>, customer_type: Option<String>, ) -> Result<GetPricingResponse>
Returns competitive pricing information for a seller’s offer listings based on seller SKU or ASIN.
§Arguments
marketplace_id- A marketplace identifier. Specifies the marketplace for which prices are returned.item_type- Indicates whether ASIN values or seller SKU values are used to identify items. Possible values: “Asin”, “Sku”.asins- A list of up to twenty Amazon Standard Identification Number (ASIN) values used to identify items in the given marketplace.skus- A list of up to twenty seller SKU values used to identify items in the given marketplace.customer_type- Indicates whether to request Consumer or Business offers. Default is “Consumer”.
§Rate Limits
- Rate: 0.5 requests per second
- Burst: 1
§Examples
let response = client.get_competitive_pricing(
"ATVPDKIKX0DER",
"Asin",
Some(vec!["B08N5WRWNW".to_string(), "B07XJ8C8F7".to_string()]),
None,
Some("Consumer".to_string()),
).await?;
println!("Competitive pricing: {:?}", response);Sourcepub async fn get_item_offers(
&self,
marketplace_id: &str,
asin: &str,
item_condition: &str,
customer_type: Option<String>,
) -> Result<GetOffersResponse>
pub async fn get_item_offers( &self, marketplace_id: &str, asin: &str, item_condition: &str, customer_type: Option<String>, ) -> Result<GetOffersResponse>
Returns the lowest priced offers for a single item based on ASIN.
§Arguments
marketplace_id- A marketplace identifier. Specifies the marketplace for which prices are returned.asin- The Amazon Standard Identification Number (ASIN) of the item for which you want to retrieve offer information.item_condition- Filters the offer listings to be considered based on item condition. Possible values: “New”, “Used”, “Collectible”, “Refurbished”, “Club”.customer_type- Indicates whether to request Consumer or Business offers. Default is “Consumer”.
§Rate Limits
- Rate: 0.5 requests per second
- Burst: 1
§Examples
let response = client.get_item_offers(
"ATVPDKIKX0DER",
"B08N5WRWNW",
"New",
Some("Consumer".to_string()),
).await?;
println!("Item offers: {:?}", response);Sourcepub async fn get_listing_offers(
&self,
marketplace_id: &str,
seller_sku: &str,
item_condition: &str,
customer_type: Option<String>,
) -> Result<GetOffersResponse>
pub async fn get_listing_offers( &self, marketplace_id: &str, seller_sku: &str, item_condition: &str, customer_type: Option<String>, ) -> Result<GetOffersResponse>
Returns the lowest priced offers for a single SKU listing.
§Arguments
marketplace_id- A marketplace identifier. Specifies the marketplace for which prices are returned.seller_sku- A seller identifier that you want to retrieve offer information for.item_condition- Filters the offer listings to be considered based on item condition. Possible values: “New”, “Used”, “Collectible”, “Refurbished”, “Club”.customer_type- Indicates whether to request Consumer or Business offers. Default is “Consumer”.
§Rate Limits
- Rate: 1 request per second
- Burst: 2
§Examples
let response = client.get_listing_offers(
"ATVPDKIKX0DER",
"MY-SKU-123",
"New",
Some("Consumer".to_string()),
).await?;
println!("Listing offers: {:?}", response);Sourcepub async fn get_item_offers_batch(
&self,
request: GetItemOffersBatchRequest,
) -> Result<GetItemOffersBatchResponse>
pub async fn get_item_offers_batch( &self, request: GetItemOffersBatchRequest, ) -> Result<GetItemOffersBatchResponse>
Returns the set of responses that correspond to the batched list of up to 20 requests defined in the request body. The response for each successful (HTTP status code 200) request in the set includes the item offers for a given ASIN.
§Arguments
request- The batch ofgetItemOffersrequests.
§Rate Limits
- Rate: 0.1 requests per second
- Burst: 1
§Examples
use spapi::models::pricing_v0::*;
let batch_request = GetItemOffersBatchRequest {
requests: Some(vec![
ItemOffersRequest {
uri: "/products/pricing/v0/items/B123456789/offers".to_string(),
method: HttpMethod::Get,
marketplace_id: "ATVPDKIKX0DER".to_string(),
item_condition: "New".to_string(),
customer_type: Some("Consumer".to_string()),
headers: None,
},
]),
};
let response = client.get_item_offers_batch(batch_request).await?;
println!("Batch item offers: {:?}", response);Sourcepub async fn get_listing_offers_batch(
&self,
request: GetListingOffersBatchRequest,
) -> Result<GetListingOffersBatchResponse>
pub async fn get_listing_offers_batch( &self, request: GetListingOffersBatchRequest, ) -> Result<GetListingOffersBatchResponse>
Returns the set of responses that correspond to the batched list of up to 20 requests defined in the request body. The response for each successful (HTTP status code 200) request in the set includes the listing offers for a given SKU.
§Arguments
request- The batch ofgetListingOffersrequests.
§Rate Limits
- Rate: 0.5 requests per second
- Burst: 1
§Examples
use spapi::models::pricing_v0::*;
let batch_request = GetListingOffersBatchRequest {
requests: Some(vec![
ListingOffersRequest {
uri: "/products/pricing/v0/listings/MY-SKU-123/offers".to_string(),
method: HttpMethod::Get,
marketplace_id: "ATVPDKIKX0DER".to_string(),
item_condition: "New".to_string(),
customer_type: Some("Consumer".to_string()),
headers: None,
},
]),
};
let response = client.get_listing_offers_batch(batch_request).await?;
println!("Batch listing offers: {:?}", response);Sourcepub async fn get_item_offers_batch_by_asins(
&self,
asins: Vec<&str>,
) -> Result<GetItemOffersBatchResponse>
pub async fn get_item_offers_batch_by_asins( &self, asins: Vec<&str>, ) -> Result<GetItemOffersBatchResponse>
Convenience method to get item offers for multiple ASINs in a single batch request.
- asins: length between 1 and 20
Examples found in repository?
5async fn main() -> Result<()> {
6 let client = SpapiClient::new(SpapiConfig::from_env()?)?;
7
8 // let res = client
9 // .get_item_offers(client.get_marketplace_id(), "B0DGJC52FP", "New", None)
10 // .await?;
11 // println!("Item offers: {:?}", res);
12
13 let res = client
14 .get_item_offers_batch_by_asins(vec!["B0DGJC52FP", "B0BN72FYFG"])
15 .await?;
16 println!("Batch item offers: {:?}", res);
17
18 // let res = client
19 // .get_listing_offers_batch_by_skus(vec!["YOU_SKU1", "YOU_SKU2"])
20 // .await?;
21 // println!("Batch listing offers: {:?}", res);
22
23
24 Ok(())
25}Sourcepub async fn get_listing_offers_batch_by_skus(
&self,
skus: Vec<&str>,
) -> Result<GetListingOffersBatchResponse>
pub async fn get_listing_offers_batch_by_skus( &self, skus: Vec<&str>, ) -> Result<GetListingOffersBatchResponse>
Convenience method to get listing offers for multiple SKUs in a single batch request.
- skus: length between 1 and 20
Source§impl SpapiClient
impl SpapiClient
Sourcepub async fn get_my_fees_estimate_for_sku(
&self,
sku: &str,
request: GetMyFeesEstimateRequest,
) -> Result<GetMyFeesEstimateResponse>
pub async fn get_my_fees_estimate_for_sku( &self, sku: &str, request: GetMyFeesEstimateRequest, ) -> Result<GetMyFeesEstimateResponse>
Get fees estimate for a product by seller SKU
Sourcepub async fn get_my_fees_estimate_for_asin(
&self,
asin: &str,
request: GetMyFeesEstimateRequest,
) -> Result<GetMyFeesEstimateResponse>
pub async fn get_my_fees_estimate_for_asin( &self, asin: &str, request: GetMyFeesEstimateRequest, ) -> Result<GetMyFeesEstimateResponse>
Get fees estimate for a product by ASIN
Sourcepub async fn get_my_fees_estimates(
&self,
requests: Vec<FeesEstimateByIdRequest>,
) -> Result<Vec<FeesEstimateResult>>
pub async fn get_my_fees_estimates( &self, requests: Vec<FeesEstimateByIdRequest>, ) -> Result<Vec<FeesEstimateResult>>
Get fees estimates for multiple products (batch operation)
Sourcepub async fn get_fee_for_asin(
&self,
asin: &str,
price: f64,
is_amazon_fulfilled: bool,
) -> Result<f64>
pub async fn get_fee_for_asin( &self, asin: &str, price: f64, is_amazon_fulfilled: bool, ) -> Result<f64>
Convenience method to get fees estimate for a single ASIN with price
Sourcepub async fn get_fees_for_asins(
&self,
asins_with_prices: Vec<(String, f64)>,
is_amazon_fulfilled: bool,
) -> Result<Vec<(String, f64)>>
pub async fn get_fees_for_asins( &self, asins_with_prices: Vec<(String, f64)>, is_amazon_fulfilled: bool, ) -> Result<Vec<(String, f64)>>
Get fees estimates for multiple ASINs (batch operation)
Source§impl SpapiClient
impl SpapiClient
Sourcepub async fn get_marketplace_participations(
&self,
) -> Result<GetMarketplaceParticipationsResponse>
pub async fn get_marketplace_participations( &self, ) -> Result<GetMarketplaceParticipationsResponse>
pub async fn get_account(&self) -> Result<GetAccountResponse>
Source§impl SpapiClient
impl SpapiClient
pub async fn cancel_report(&self, report_id: &str) -> Result<()>
pub async fn cancel_report_schedule( &self, report_schedule_id: &str, ) -> Result<()>
pub async fn create_report( &self, body: CreateReportSpecification, ) -> Result<CreateReportResponse>
pub async fn create_report_schedule( &self, body: CreateReportScheduleSpecification, ) -> Result<CreateReportScheduleResponse>
pub async fn get_report(&self, report_id: &str) -> Result<Report>
pub async fn get_report_document( &self, report_document_id: &str, ) -> Result<ReportDocument>
pub async fn get_report_schedule( &self, report_schedule_id: &str, ) -> Result<ReportSchedule>
pub async fn get_report_schedules( &self, report_types: Vec<String>, ) -> Result<ReportScheduleList>
pub async fn get_reports( &self, report_types: Option<Vec<String>>, processing_statuses: Option<Vec<String>>, marketplace_ids: Option<Vec<String>>, page_size: Option<i32>, created_since: Option<String>, created_until: Option<String>, next_token: Option<&str>, ) -> Result<GetReportsResponse>
Sourcepub async fn fetch_report(
&self,
report_type: &str,
marketplace_ids: Vec<String>,
max_wait_minutes: Option<u32>,
progress_callback: Option<impl Fn(u32, ProcessingStatus) + Send + 'static>,
) -> Result<String>
pub async fn fetch_report( &self, report_type: &str, marketplace_ids: Vec<String>, max_wait_minutes: Option<u32>, progress_callback: Option<impl Fn(u32, ProcessingStatus) + Send + 'static>, ) -> Result<String>
Convenience method to fetch a report by type and marketplace IDs, defaulting to a 30-minute wait.
Examples found in repository?
179async fn main() -> Result<()> {
180 env_logger::init();
181
182 let spapi_config = SpapiConfig::from_env()?;
183 let client = SpapiClient::new(spapi_config.clone())?;
184 let marketplace_ids = vec!["ATVPDKIKX0DER".to_string()]; // Amazon US Marketplace ID
185
186 // create report specification
187 let report_type = "GET_RESTOCK_INVENTORY_RECOMMENDATIONS_REPORT";
188 let report_content = client
189 .fetch_report(
190 report_type,
191 marketplace_ids.clone(),
192 None,
193 Some(|attempt, status| {
194 println!("Attempt get report {}: {:?}", attempt, status);
195 }),
196 )
197 .await?;
198
199 // save report content to a file
200 let report_file_path = "/tmp/restock_inventory_report.txt";
201 std::fs::write(report_file_path, &report_content)
202 .expect("Unable to write report content to file");
203
204 // // load report content from the file
205 // let report_file_path = "/tmp/restock_inventory_report.txt";
206 // let report_content =
207 // std::fs::read_to_string(report_file_path).expect("Unable to read report content from file");
208
209 let restocks = parse_restock_report(&report_content);
210
211 println!("Restock inventory report generated successfully.");
212 println!("{:#?}", restocks);
213
214 Ok(())
215}