A Rust client library for Amazon Selling Partner API (SP-API), providing complete API coverage and type-safe interfaces.
- Complete API Coverage: Auto-generated API models from OpenAPI specifications covering nearly all Amazon SP-API endpoints
- Integrated Client: High-level client wrapper with convenient methods for common API operations
First, set up your Amazon SP-API credentials as environment variables:
export SPAPI_CLIENT_ID="your_client_id"
export SPAPI_CLIENT_SECRET="your_client_secret"
export SPAPI_REFRESH_TOKEN="your_refresh_token"
export SPAPI_MARKETPLACE_ID="your_marketplace_id"
export SPAPI_SANDBOX="false" # or "true" for sandbox environment
use amazon_spapi::{
client::{SpapiClient, SpapiConfig},
models::fba_inventory::InventorySummary,
};
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Create client from environment variables
let client = SpapiClient::new(SpapiConfig::from_env()?)?;
// Get FBA inventory summaries
let inventory = client
.get_inventory_summaries(
"Marketplace",
client.get_marketplace_id(),
vec![client.get_marketplace_id().to_string()],
Some(false),
None,
None,
None,
None,
)
.await?;
println!("Inventory summaries: {:?}", inventory);
Ok(())
}
For advanced usage and access to all API methods, you can use the auto-generated APIs directly. This approach gives you access to every Amazon SP-API endpoint:
use amazon_spapi::apis::sellers_api::get_marketplace_participations;
use amazon_spapi::client::{SpapiClient, SpapiConfig};
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
let spapi_config = SpapiConfig::from_env()?;
let spapi_client = SpapiClient::new(spapi_config.clone())?;
{
// Internally refresh the access token and create a configuration
// Configuration must be created for each API call
let configuration = spapi_client.create_configuration().await?;
// Wait for rate limit before making the API call
// When _guard is dropped, the rate limiter will mark the api call as having received a response
let _guard = spapi_client
.limiter()
.wait("get_marketplace_participations", 0.016, 15)
.await?;
// Call the API to get marketplace participations
let res = get_marketplace_participations(&configuration).await?;
println!("Marketplace Participations: {:#?}", res);
}
Ok(())
}
This approach provides:
- Complete API Access: All Amazon SP-API endpoints are available
- Type Safety: Full type checking for all request/response models
- Rate Limiting: Built-in rate limiting management
- Flexibility: Direct access to all API parameters and options
You can find all available API functions in the amazon_spapi::apis
module, organized by API category.
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This is an unofficial Amazon SP-API Rust client library. Please ensure compliance with Amazon's terms of service and API limitations.