Sample code for 30+ languages & platforms
Rust

Amazon SP-API Create Feed Doc

See more Amazon SP-API Examples

Creates a feed document. Amazon returns a feedDocumentId value, encryption details, and a URL for uploading the feed contents.

Chilkat Rust Downloads

Rust

// 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("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 json_req = chilkat::JsonObject::new();
let _ = json_req.update_string("contentType", "text/tab-separated-values; charset=UTF-8");

let sb_request = chilkat::StringBuilder::new();
let _ = json_req.emit_sb(&sb_request);

let _ = rest.clear_all_query_params();
let _ = rest.clear_all_headers();
let _ = rest.add_header("x-amz-access-token", &lwa_token);

let sb_response = chilkat::StringBuilder::new();
let path = "/feeds/2021-06-30/documents".to_string();
if rest.full_request_sb("POST", &path, &sb_request, &sb_response).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

// Examine the response status.
let status_code = rest.response_status_code();
println!("statusCode: {}", status_code);

if status_code != 201 {
    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:

// {
//   "feedDocumentId": "3d4e42b5-1d6e-44e8-a89c-2abfca0625bb",
//   "url": "https://d34o8swod1owfl.cloudfront.net/Feed_101__POST_PRODUCT_DATA_.xml"
// }

// 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 feed_document_id = json.string_of("feedDocumentId").unwrap_or_default();
let url = json.string_of("url").unwrap_or_default();

// Save the JSON to a file for the example that uploads the feed..
let _ = json.write_file("qa_data/json/sp_api_feed_upload_info.json").is_ok();

println!("Success!");