Rust
Rust
MercadoLibre - Cargar factura (Upload Invoice)
See more MercadoLibre Examples
Cargar factura en detalle de ventaChilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// First get our previously obtained OAuth2 access token.
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/mercadolibre.json").is_ok();
// Implements the following CURL command:
// curl -X POST https://api.mercadolibre.com/packs/$PACK_ID/fiscal_documents?access_token=$ACCESS_TOKEN
// -H 'content-type: multipart/form-data;'
// -F 'fiscal_document=@/home/user/.../Factura_adjunta.pdf'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
let sb_path = chilkat::StringBuilder::new();
let _ = sb_path.append("/packs/$PACK_ID/fiscal_documents?access_token=$ACCESS_TOKEN");
// Use an actual pack ID.
let mut num_replaced = sb_path.replace("$PACK_ID", "2000000089077943");
num_replaced = sb_path.replace("$ACCESS_TOKEN", &json_token.string_of("access_token").unwrap_or_default());
let req = chilkat::HttpRequest::new();
req.set_http_verb("POST");
req.set_path(&sb_path.get_as_string().unwrap_or_default());
req.set_content_type("multipart/form-data");
let _ = req.add_file_for_upload2("fiscal_document", "/home/user/.../Factura_adjunta.pdf", "application/pdf").is_ok();
req.add_header("Expect", "100-continue");
req.add_header("content-type", "multipart/form-data;");
let resp = chilkat::HttpResponse::new();
if http.http_s_req("api.mercadolibre.com", 443, true, &req, &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "ids": [
// "415460047_a96d8dea-38cd-4402-938e-80a1c134fc5d"
// ]
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let mut i = 0;
let count_i = j_resp.size_of_array("ids");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("ids[i]").unwrap_or_default();
i = i + 1;
}