Rust
Rust
Amazon SP-API Get Feeds
See more Amazon SP-API Examples
Returns feed details for the feeds that match the filters that you specify.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();
if rest.connect("sandbox.sellingpartnerapi-eu.amazon.com", 443, true, true).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 _ = rest.clear_all_query_params();
let _ = rest.add_query_param("feedTypes", "POST_PRODUCT_DATA");
let _ = rest.add_query_param("pageSize", "10");
let _ = rest.add_query_param("processingStatuses", "CANCELLED,DONE");
let sb_response = chilkat::StringBuilder::new();
let path = "/feeds/2021-06-30/feeds".to_string();
if rest.full_request_no_body_sb("GET", &path, &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:
// {
// "feeds": [
// {
// "feedId": "FeedId1",
// "feedType": "POST_PRODUCT_DATA",
// "createdTime": "2019-12-11T13:16:24.630Z",
// "processingStatus": "CANCELLED",
// "processingStartTime": "2019-12-11T13:16:24.630Z",
// "processingEndTime": "2019-12-11T13:16:24.630Z"
// }
// ],
// "nextToken": "VGhpcyB0b2tlbiBpcyBvcGFxdWUgYW5kIGludGVudGlvbmFsbHkgb2JmdXNjYXRlZA=="
// }
// 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 next_token = json.string_of("nextToken").unwrap_or_default();
let mut i = 0;
let count_i = json.size_of_array("feeds");
while i < count_i {
json.set_i(i);
let _ = json.string_of("feeds[i].feedId").unwrap_or_default();
let _ = json.string_of("feeds[i].feedType").unwrap_or_default();
let _ = json.string_of("feeds[i].createdTime").unwrap_or_default();
let _ = json.string_of("feeds[i].processingStatus").unwrap_or_default();
let _ = json.string_of("feeds[i].processingStartTime").unwrap_or_default();
let _ = json.string_of("feeds[i].processingEndTime").unwrap_or_default();
i = i + 1;
}
println!("Success!");