Struct SpapiConfig

Source
pub struct SpapiConfig {
    pub client_id: String,
    pub client_secret: String,
    pub refresh_token: String,
    pub marketplace_id: String,
    pub region: String,
    pub sandbox: bool,
    pub user_agent: Option<String>,
    pub timeout_sec: Option<u64>,
}

Fields§

§client_id: String§client_secret: String§refresh_token: String§marketplace_id: String§region: String§sandbox: bool§user_agent: Option<String>§timeout_sec: Option<u64>

Implementations§

Source§

impl SpapiConfig

Source

pub fn from_env() -> Result<Self>

Examples found in repository?
examples/sellers_v1.rs (line 6)
5async fn main() -> Result<()> {
6    let config = SpapiConfig::from_env()?;
7    let client = SpapiClient::new(config.clone())?;
8
9    let marketplace = client.get_marketplace_participations().await?;
10    println!("Marketplace: {:#?}", marketplace);
11    println!("{}", marketplace.payload.ok()?[0].marketplace.name);
12
13    Ok(())
14}
More examples
Hide additional examples
examples/fba_inventory_v1.rs (line 49)
48async fn main() -> Result<()> {
49    let client = SpapiClient::new(SpapiConfig::from_env()?)?;
50
51    let inventory_summaries = get_inventory_summaries_all(&client, Some(false)).await?;
52    log::info!("Fetched {} inventory summaries", inventory_summaries.len());
53    for summary in inventory_summaries {
54        log::info!("Inventory Summary: {:?}", summary);
55    }
56
57    Ok(())
58}
examples/pricing_v0.rs (line 6)
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}
examples/sellers_v1_use_raw_api.rs (line 7)
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}
examples/product_fees_v0.rs (line 6)
5async fn main() -> Result<()> {
6    let client = SpapiClient::new(SpapiConfig::from_env()?)?;
7
8    // let fee = client.get_fee_for_asin("B0DGJC52FP", 999.0, true).await?;
9    // println!("Fee for ASIN B0DGJC52FP: ${:.2}", fee);
10
11    let current_local_time = chrono::Local::now();
12    println!("Current local time: {}", current_local_time);
13    {
14        let fees = client
15            .get_fees_for_asins(vec![("B0DGJC52FP".to_string(), 999.0)], true)
16            .await?;
17        println!("Fees for ASINs: {:?}", fees);
18    }
19    let current_local_time = chrono::Local::now();
20    println!("Current local time: {}", current_local_time);
21    {
22        let fees = client
23            .get_fees_for_asins(vec![("B0DGJC52FP".to_string(), 999.0)], true)
24            .await?;
25        println!("Fees for ASINs: {:?}", fees);
26    }
27    let current_local_time = chrono::Local::now();
28    println!("Current local time: {}", current_local_time);
29    {
30        let fees = client
31            .get_fees_for_asins(vec![("B0DGJC52FP".to_string(), 999.0)], true)
32            .await?;
33        println!("Fees for ASINs: {:?}", fees);
34    }
35    let current_local_time = chrono::Local::now();
36    println!("Current local time: {}", current_local_time);
37
38    Ok(())
39}
examples/reports.rs (line 182)
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}

Trait Implementations§

Source§

impl Clone for SpapiConfig

Source§

fn clone(&self) -> SpapiConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpapiConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SpapiConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SpapiConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,