Rust
Rust
effectconnect Product Update
See more effectconnect Examples
Use this call to update a product (f.e. stock or price) in EffectConnect.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let uri = "/products".to_string();
let api_version = "2.0".to_string();
let http = chilkat::Http::new();
let req = chilkat::HttpRequest::new();
// Use your effectconnect public key here...
req.add_header("KEY", "PUBLIC_KEY");
req.add_header("VERSION", &api_version);
req.add_header("URI", &uri);
req.add_header("RESPONSETYPE", "XML");
req.add_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();
req.add_header("TIME", ×tamp);
println!("timestamp = {}", timestamp);
let sb_xml = chilkat::StringBuilder::new();
let _ = sb_xml.load_file("qa_data/xml/effectconnect/effconUpdate.xml", "utf-8").is_ok();
println!("length = {}", sb_xml.length());
req.set_http_verb("PUT");
req.set_path(&uri);
req.set_content_type("multipart/form-data");
if req.add_string_for_upload("payload", "effconUpdate.xml", &sb_xml.get_as_string().unwrap_or_default(), "utf-8").is_err() {
println!("{}", req.last_error_text());
return;
}
// 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("PUT");
let _ = sb_string_to_sign.append(&uri);
let _ = sb_string_to_sign.append(&api_version);
let _ = sb_string_to_sign.append(×tamp);
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");
req.add_header("SIGNATURE", &crypt.mac_string_enc(&sb_string_to_sign.get_as_string().unwrap_or_default()).unwrap_or_default());
let resp = chilkat::HttpResponse::new();
if http.http_s_req("submit.effectconnect.com", 443, true, &req, &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());
// A sample response:
// <?xml version="1.0" encoding="utf-8"?>
// <ApiResponseContainer>
// <Request>
// <RequestType>Products</RequestType>
// <RequestAction>Update</RequestAction>
// <RequestVersion>2.0</RequestVersion>
// <RequestIdentifier/>
// <ProcessedAt>2019-04-18T15:37:32+02:00</ProcessedAt>
// </Request>
// <Response>
// <Result>Success</Result>
// <ProductsUpdateResponseContainer>
// <ProcessID><![CDATA[f81ngzD2S7gooFk3]]></ProcessID>
// </ProductsUpdateResponseContainer>
// </Response>
// </ApiResponseContainer>
//
let request_type = xml_resp.get_child_content("Request|RequestType").unwrap_or_default();
let request_action = xml_resp.get_child_content("Request|RequestAction").unwrap_or_default();
let request_version = xml_resp.get_child_content("Request|RequestVersion").unwrap_or_default();
let processed_at = xml_resp.get_child_content("Request|ProcessedAt").unwrap_or_default();
let result = xml_resp.get_child_content("Response|Result").unwrap_or_default();
let process_id = xml_resp.get_child_content("Response|ProductsUpdateResponseContainer|ProcessID").unwrap_or_default();