Rust
Rust
SII POST boleta.electronica.envio
See more SII Chile Examples
Almacenamiento de un conjunto de boletas en el SIIChilkat 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();
// Implements the following CURL command:
// curl -X POST "https://pangal.sii.cl/recursos/v1/boleta.electronica.envio" -H "accept: application/json"
// -H "User-Agent: Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)"
// -H "Cookie: YZVQNQY4J5DT9" -H "Content-Type: multipart/form-data"
// -F "rutSender=1234" -F "dvSender=xyz" -F "rutCompany=9999" -F "dvCompany=abc"
// -F "archivo=@starfish20.jpg;type=image/jpeg"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
let req = chilkat::HttpRequest::new();
req.set_http_verb("POST");
req.set_path("/recursos/v1/boleta.electronica.envio");
req.set_content_type("multipart/form-data");
req.add_param("rutSender", "66666666");
req.add_param("dvSender", "6");
req.add_param("rutCompany", "60803000");
req.add_param("dvCompany", "K");
// Add an XML file that contains something like this:
// <?xml version="1.0" encoding="ISO-8859-1"?>
// <EnvioBOLETA version="1.0" xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioBOLETA_v11.xsd">
// <SetDTE ID="SetDocB0T39_20201103_131999">
// <Caratula version="1.0">
// ...
let xml_str = "...".to_string();
let _ = req.add_string_for_upload2("archivo", "envioBoleta.xml", &xml_str, "ISO-8859-1", "text/xml").is_ok();
req.add_header("Expect", "100-continue");
req.add_header("User-Agent", "Mozilla/4.0 ( compatible; PROG 1.0; Windows NT)");
req.add_header("Cookie", "TOKEN=YZVQNQY4J5DT9");
req.add_header("accept", "application/json");
req.add_header("Content-Type", "multipart/form-data");
// For debugging, you can save the exact HTTP request sent and response received
// to a session log file:
http.set_session_log_filename("someDir/sessionLog.txt");
// Use one of the following domains, depending on the environment:
// pangal.sii.cl - Certification Environment
// rahue.sii.cl - Production Environment
let resp = chilkat::HttpResponse::new();
if http.http_s_req("pangal.sii.cl", 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)
// {
// "rut_emisor": "45000054-K",
// "rut_envia": "83154595-0",
// "trackid": 1014,
// "fecha_recepcion": "2020-09-01 20:30:10",
// "estado": "REC",
// "file": "boleta-2020-09-01-001.xml"
// }
// 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 rut_emisor = j_resp.string_of("rut_emisor").unwrap_or_default();
let rut_envia = j_resp.string_of("rut_envia").unwrap_or_default();
let trackid = j_resp.int_of("trackid");
let fecha_recepcion = j_resp.string_of("fecha_recepcion").unwrap_or_default();
let estado = j_resp.string_of("estado").unwrap_or_default();
let file = j_resp.string_of("file").unwrap_or_default();