Sample code for 30+ languages & platforms
JavaScript

Shopware Delete Media

See more Shopware Examples

Demonstrates how to delete a media file from a Shopware shop.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

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

var http = new CkHttp();

http.Login = "api_username";
http.Password = "api_key";
http.BasicAuth = true;

// The id of the product is appended to the path part of the URL.
http.SetUrlVar("id","6864");

var url = "https://my-shopware-shop.com/api/media/{$id}";

// Send a DELETE request with nothing in the request body.
var resp = new CkHttpResponse();
success = http.HttpNoBody("DELETE",url,resp);
if (success == false) {
    console.log(http.LastErrorText);
    return;
}

var sbResponseBody = new CkStringBuilder();
resp.GetBodySb(sbResponseBody);

var jResp = new CkJsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;

console.log("Response Body:");
console.log(jResp.Emit());

// A 200 response code indicates success (i.e. the request was sent and a response was received).
var respStatusCode = resp.StatusCode;
console.log("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
    console.log("Response Header:");
    console.log(resp.Header);
    console.log("Failed.");
    return;
}

// Sample JSON response:

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

var bDeleted = jResp.BoolOf("success");
console.log("Deleted: " + bDeleted);

// A failed response would look like this:

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