Sample code for 30+ languages & platforms
Rust

WooCommerce List Products having SKU

See more WooCommerce Examples

Gets information for a product by SKU.

Chilkat Rust Downloads

Rust

// 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 https://example.com/wp-json/wc/v3/products?sku=3386460107914 \
//     -u consumer_key:consumer_secret

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

http.set_basic_auth(true);
http.set_login("consumer_key");
http.set_password("consumer_secret");

let sb_response_body = chilkat::StringBuilder::new();
let _ = http.set_url_var("sku", "3386460107914");
// Use "https" or "http" depending on what your site needs.
if http.quick_get_sb("http://example.com/wp-json/wc/v3/products?sku={$sku}", &sb_response_body).is_err() {
    println!("{}", http.last_error_text());
    return;
}

let jarr_resp = chilkat::JsonArray::new();
let _ = jarr_resp.load_sb(&sb_response_body);
jarr_resp.set_emit_compact(false);

println!("Response Body:");
println!("{}", jarr_resp.emit().unwrap_or_default());

let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
    println!("Response Header:");
    println!("{}", http.last_header());
    println!("Failed.");
    return;
}