Sample code for 30+ languages & platforms
Rust

Shopware Update Product Data

See more Shopware Examples

Update information about an existing product in Shopware.

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();

http.set_login("api_username");
http.set_password("api_key");
http.set_basic_auth(true);

// The following JSON is sent in the request body.

// {
//   "name": "Super-Duper Sports Shoes"
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("name", "Super-Duper Sports Shoes");

// The id of the product is appended to the path part of the URL.
let _ = http.set_url_var("id", "8312");

let url = "https://my-shopware-shop.com/api/articles/{$id}".to_string();
let resp = chilkat::HttpResponse::new();
if http.http_json("PUT", &url, &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());

// A 200 response code indicates success.
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)

// {
//   "success": true,
//   "data": {
//     "id": 8312,
//     "location": "https:\/\/my-shopware-shop.com\/api\/articles\/8312"
//   }
// }

// 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 _ = j_resp.bool_of("success");
let data_id = j_resp.int_of("data.id");
let data_location = j_resp.string_of("data.location").unwrap_or_default();