Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

effectconnect Read Orderlist

See more effectconnect Examples

Get a set of orders filtered by the parameters in the XML payload.

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let full_uri = "https://submit.effectconnect.com/orderlist".to_string();
let uri = "/orderlist".to_string();
let api_version = "2.0".to_string();

let http = chilkat::Http::new();

// Use your effectconnect public key here..
http.set_request_header("KEY", "PUBLIC_KEY");
http.set_request_header("VERSION", &api_version);
http.set_request_header("URI", &uri);
http.set_request_header("RESPONSETYPE", "XML");
http.set_request_header("RESPONSELANGUAGE", "en");

// Get the current date/time in timestamp format.
let dt = chilkat::DateTime::new();
let _ = dt.set_from_current_system_time();
let timestamp = dt.get_as_timestamp(true).unwrap_or_default();

http.set_request_header("TIME", &timestamp);
println!("timestamp = {}", timestamp);

// Create the following XML request body:
// <?xml version="1.0" encoding="utf-8"?>
// <list>
//   <filters>
//     <fromDateFilter>
//       <filterValue>2018-09-14T12:12:12+01:00</filterValue>
//     </fromDateFilter>
//     <toDateFilter>
//       <filterValue>2019-04-13T23:59:59+01:00</filterValue>
//     </toDateFilter>
//     <hasStatusFilter>
//       <filterValue>paid</filterValue>
//     </hasStatusFilter>
//     <hasTagFilter>
//       <filterValue>
//         <tagName>Test</tagName>
//         <exclude>false</exclude>
//       </filterValue>
//     </hasTagFilter>
//   </filters>
// </list>

// Use this online tool to generate the code from sample XML: 
// Generate Code to Create XML

let xml = chilkat::Xml::new();
xml.set_tag("list");
xml.update_child_content("filters|fromDateFilter|filterValue", "2018-09-14T12:12:12+01:00");
xml.update_child_content("filters|toDateFilter|filterValue", "2019-04-13T23:59:59+01:00");
xml.update_child_content("filters|hasStatusFilter|filterValue", "paid");
xml.update_child_content("filters|hasTagFilter|filterValue|tagName", "Test");
xml.update_child_content("filters|hasTagFilter|filterValue|exclude", "false");
xml.set_emit_compact(true);

let sb_xml = chilkat::StringBuilder::new();
let _ = xml.get_xml_sb(&sb_xml);

// Build a string-to-sign and sign it using our effectconnect private key
let sb_string_to_sign = chilkat::StringBuilder::new();
let _ = sb_string_to_sign.append_int(sb_xml.length());
let _ = sb_string_to_sign.append("POST");
let _ = sb_string_to_sign.append(&uri);
let _ = sb_string_to_sign.append(&api_version);
let _ = sb_string_to_sign.append(&timestamp);

let crypt = chilkat::Crypt2::new();
crypt.set_mac_algorithm("hmac");
crypt.set_hash_algorithm("sha512");
crypt.set_encoding_mode("base64");
// Use your effectconnect private key here:
let _ = crypt.set_mac_key_string("PRIVATE_KEY");
http.set_request_header("SIGNATURE", &crypt.mac_string_enc(&sb_string_to_sign.get_as_string().unwrap_or_default()).unwrap_or_default());

// Send the POST..
let resp = chilkat::HttpResponse::new();
if http.http_str("POST", &full_uri, &xml.get_xml().unwrap_or_default(), "utf-8", "application/xml", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

println!("response status code = {}", resp.status_code());

// Examine the response.  The response status code can be 200 for both errors and success.
// The success or error is based on the XML returned in the response body.
let xml_resp = chilkat::Xml::new();
let _ = xml_resp.load_xml(&resp.body_str());

println!("response body:");
println!("{}", xml_resp.get_xml().unwrap_or_default());

// Remove previously set headers (unless we want the same headers for the next request,
// in which case we may remove or update individual headers by calling SetRequestHeader.
http.clear_headers();