Rust
Rust
Amazon MWS Upload Invoice
See more Amazon MWS Examples
Demonstrates how to upload an invoice using _UPLOAD_VAT_INVOICE_FeedType to submit an invoice for an order.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = chilkat::Rest::new();
// Connect to the Amazon MWS REST server.
//
// Make sure to connect to the correct Amazon MWS Endpoint, otherwise
// you'll get an HTTP 401 response code.
//
// See Amazon MWS endpoints and MarketplaceId values
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
let _ = rest.connect("mws.amazonservices.com", port, b_tls, b_auto_reconnect).is_ok();
rest.set_host("mws.amazonservices.com");
// MarketplaceList.Id parameter �This should be the marketplace in which the order was placed. Only one marketplace must be used per order.T
// Here are the marketplace ID's
// Spain: A1RKKUPIHCS9HS
// UK: A1F83G8C2ARO7P
// France: A13V1IB3VIYZZH
// Germany: A1PA6795UKMFR9
// Italy: APJ6JRA9NG5V4
// ...
// (See https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html)
// FeedOptions parameter � Seller can input key value pairs to give important metadata along with the PDF invoice.
let _ = rest.add_query_param("FeedOptions", "metadata:orderid=206-2341234-3455465;metadata:invoicenumber=INT-3431-XJE3;metadata:documenttype=Invoice");
// Load the PDF invoice file that is to be the body of the HTTP POST request.
let pdf_data = chilkat::BinData::new();
let _ = pdf_data.load_file("qa_data/pdf/sample.pdf").is_ok();
// Get the MD5 hash of the PDF data.
let crypt = chilkat::Crypt2::new();
crypt.set_hash_algorithm("md5");
crypt.set_encoding_mode("base64");
let md5_hash = crypt.hash_bd_enc(&pdf_data).unwrap_or_default();
let _ = rest.add_query_param("AWSAccessKeyId", "0PB842ExampleN4ZTR2");
let _ = rest.add_query_param("Action", "SubmitFeed");
let _ = rest.add_query_param("FeedType", "_UPLOAD_VAT_INVOICE_");
let _ = rest.add_query_param("MWSAuthToken", "EXAMPLE-amzn.mws.4ea38b7b-f563-7709-4bae-87aea-EXAMPLE");
let _ = rest.add_query_param("MarketplaceIdList.Id.1", "ATVExampleDER");
let _ = rest.add_query_param("SellerId", "A1XExample5E6");
let _ = rest.add_query_param("ContentMD5Value", &md5_hash);
let _ = rest.add_query_param("SignatureMethod", "HmacSHA256");
let _ = rest.add_query_param("SignatureVersion", "2");
let _ = rest.add_query_param("Version", "2009-01-01");
// Add the MWS Signature param. (Also adds the Timestamp parameter using the curent system date/time.)
let _ = rest.add_mws_signature("POST", "/Feeds/2009-01-01", "mws.amazonservices.com", "YOUR_MWS_SECRET_ACCESS_KEY_ID");
let _ = rest.add_header("Content-Type", "application/octet-stream");
let sb_response_body = chilkat::StringBuilder::new();
let _ = rest.full_request_bd("POST", "/Feeds/2009-01-01", &pdf_data, &sb_response_body).is_ok();
if !rest.last_method_success() {
println!("{}", rest.last_error_text());
return;
}
if rest.response_status_code() != 200 {
// Examine the request/response to see what happened.
println!("response status code = {}", rest.response_status_code());
println!("response status text = {}", rest.response_status_text());
println!("response header: {}", rest.response_header());
println!("response body: {}", sb_response_body.get_as_string().unwrap_or_default());
println!("---");
println!("LastRequestStartLine: {}", rest.last_request_start_line());
println!("LastRequestHeader: {}", rest.last_request_header());
}
// Examine the XML returned in the response body.
println!("{}", sb_response_body.get_as_string().unwrap_or_default());
println!("----");
println!("Success.");