Rust
Rust
Aruba Fatturazione Elettronica CreateTransmissionRequestList
See more Aruba Fatturazione Examples
Creation of "Financial Communications" transmission request in zip format.Chilkat 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://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList \
// -H "Accept: application/json" \
// -H "Content-Type: application/json;charset=UTF-8" \
// -d '{
// "userName" : "ARUBA0000",
// "password" : "ArubaPwd",
// "userID" : "ARUBA0000",
// "comunicationType" : "LI",
// "dataFile" : "dGVzdA=="
// }'
// The dataFile must contain a Zip file, containing xml files which conform to the Revenue Agency specifications.
// The archive file must be Base64 codified and contain a CADES-based electronic signature.
let zip = chilkat::Zip::new();
// Initialize the zip object. Because we will never actually write a zip file to the filesystem,
// the filepath passed to NewZip does not matter.
let _ = zip.new_zip("x.zip");
// Append references to XML files to the zip object in memory.
let recurse = false;
if zip.append_files("qa_data/aruba/*.xml", recurse).is_err() {
println!("{}", zip.last_error_text());
return;
}
// Write the zip archive into the bdZip object.
let bd_zip = chilkat::BinData::new();
if zip.write_bd(&bd_zip).is_err() {
println!("{}", zip.last_error_text());
return;
}
// Get the zip in base64 format.
let zip_as_base64 = bd_zip.get_encoded("base64").unwrap_or_default();
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "userName": "ARUBA0000",
// "password": "ArubaPwd",
// "userID": "ARUBA0000",
// "comunicationType": "LI",
// "dataFile": "dGVzdA=="
// }
let json = chilkat::JsonObject::new();
let _ = json.update_string("userName", "ARUBA0000");
let _ = json.update_string("password", "ArubaPwd");
let _ = json.update_string("userID", "ARUBA0000");
let _ = json.update_string("comunicationType", "LI");
let _ = json.update_string("dataFile", &zip_as_base64);
http.set_request_header("Content-Type", "application/json;charset=UTF-8");
http.set_request_header("Accept", "application/json");
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://ws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList", &json, "application/json", &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)
// {
// "errorCode": "",
// "errorDescription": "",
// "requestID": "C70WC0SIPQ1JISWQ",
// "requestIDList": [
// {
// "fileName": "ITADFSREETDSD_LI_0001.xml",
// "requestID": "TXZWQPVYVFJHRUKN"
// },
// {
// "fileName": "ITADFSREETDSD_LI_0002.xml",
// "requestID": "PRSGFITDHFPTJ8OO"
// },
// {
// "fileName": "ITADFSREETDSD_LI_0003.xml",
// "requestID": "QNJ9E2MWGYGSM22Q"
// }
// ]
// }
// 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 error_code = j_resp.string_of("errorCode").unwrap_or_default();
let error_description = j_resp.string_of("errorDescription").unwrap_or_default();
let mut request_id = j_resp.string_of("requestID").unwrap_or_default();
let mut i = 0;
let count_i = j_resp.size_of_array("requestIDList");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("requestIDList[i].fileName").unwrap_or_default();
request_id = j_resp.string_of("requestIDList[i].requestID").unwrap_or_default();
i = i + 1;
}