(JavaScript) ShopwareDelete Product
Deletes a product in Shopware.For more information, see https://developers.shopware.com/developers-guide/rest-api/examples/article/#example-4-delete-a-product
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","8312");
var url = "https://my-shopware-shop.com/api/articles/{$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\" 8312 not found"
// }
|