Rust
Rust
Amazon SP-API Sellers Get Marketplace Participations
See more Amazon SP-API Examples
Demonstrates Amazon SP-API Sellers API -- get marketplace participations.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let auth_aws = chilkat::AuthAws::new();
auth_aws.set_access_key("AWS_ACCESS_KEY");
auth_aws.set_secret_key("AWS_SECRET_KEY");
auth_aws.set_service_name("execute-api");
// Use the region that is correct for your needs.
auth_aws.set_region("eu-west-1");
let rest = chilkat::Rest::new();
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
// Make sure to use the correct domain.
// In this example, we are using "sandbox.sellingpartnerapi-eu.amazon.com"
if rest.connect("sandbox.sellingpartnerapi-eu.amazon.com", port, b_tls, b_auto_reconnect).is_err() {
println!("{}", rest.last_error_text());
return;
}
let _ = rest.set_auth_aws(&auth_aws).is_ok();
// Load the previously obtained LWA access token.
// See Fetch SP-API LWA Access Token
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/sp_api_lwa_token.json").is_err() {
println!("Failed to load LWA access token.");
return;
}
// Add the x-amz-access-token request header.
let lwa_token = json_token.string_of("access_token").unwrap_or_default();
let _ = rest.clear_all_headers();
let _ = rest.add_header("x-amz-access-token", &lwa_token);
let sb_response = chilkat::StringBuilder::new();
let uri = "/sellers/v1/marketplaceParticipations".to_string();
if rest.full_request_no_body_sb("GET", &uri, &sb_response).is_err() {
println!("{}", rest.last_error_text());
return;
}
// Examine the response status.
let status_code = rest.response_status_code();
if status_code != 200 {
println!("Response status text: {}", rest.response_status_text());
println!("Response body: ");
println!("{}", sb_response.get_as_string().unwrap_or_default());
println!("Failed.");
return;
}
println!("{}", sb_response.get_as_string().unwrap_or_default());
// If successful, gets a JSON response such as the following:
// {
// "payload": [
// {
// "marketplace": {
// "id": "ATVPDKIKX0DER",
// "countryCode": "US",
// "name": "Amazon.com",
// "defaultCurrencyCode": "USD",
// "defaultLanguageCode": "en_US",
// "domainName": "www.amazon.com"
// },
// "participation": {
// "isParticipating": true,
// "hasSuspendedListings": false
// }
// }
// ]
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let json = chilkat::JsonObject::new();
let _ = json.load_sb(&sb_response);
let mut i = 0;
let count_i = json.size_of_array("payload");
while i < count_i {
json.set_i(i);
let _ = json.string_of("payload[i].marketplace.id").unwrap_or_default();
let _ = json.string_of("payload[i].marketplace.countryCode").unwrap_or_default();
let _ = json.string_of("payload[i].marketplace.name").unwrap_or_default();
let _ = json.string_of("payload[i].marketplace.defaultCurrencyCode").unwrap_or_default();
let _ = json.string_of("payload[i].marketplace.defaultLanguageCode").unwrap_or_default();
let _ = json.string_of("payload[i].marketplace.domainName").unwrap_or_default();
let _ = json.bool_of("payload[i].participation.isParticipating");
let _ = json.bool_of("payload[i].participation.hasSuspendedListings");
i = i + 1;
}
println!("Success!");