Sample code for 30+ languages & platforms
Node.js

Shopware Delete Media

See more Shopware Examples

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

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

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

    var http = new chilkat.Http();

    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 chilkat.HttpResponse();
    success = http.HttpNoBody("DELETE",url,resp);
    if (success == false) {
        console.log(http.LastErrorText);
        return;
    }

    var sbResponseBody = new chilkat.StringBuilder();
    resp.GetBodySb(sbResponseBody);

    var jResp = new chilkat.JsonObject();
    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"
    //  }

}

chilkatExample();