Sample code for 30+ languages & platforms
Rust

Shopware Delete Media

See more Shopware Examples

Demonstrates how to delete a media file from a Shopware shop.

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 id of the product is appended to the path part of the URL.
let _ = http.set_url_var("id", "6864");

let url = "https://my-shopware-shop.com/api/media/{$id}".to_string();

// Send a DELETE request with nothing in the request body.
let resp = chilkat::HttpResponse::new();
if http.http_no_body("DELETE", &url, &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 (i.e. the request was sent and a response was received).
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:

// {
//   "success": true
// }

let b_deleted = j_resp.bool_of("success");
println!("Deleted: {}", b_deleted);

// A failed response would look like this:

// {
//   "success": false,
//   "message": "Product by \"id\" 6864 not found"
// }