Sample code for 30+ languages & platforms
Lua

ShopwareDelete Product

See more Shopware Examples

Deletes a product in Shopware.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

http.login = "api_username"
http.password = "api_key"
http.basic_auth = true

-- The id of the product is appended to the path part of the URL.
http:set_url_var("id", "8312")

local url = "https://my-shopware-shop.com/api/articles/{$id}"

-- Send a DELETE request with nothing in the request body.
local resp = chilkat.HttpResponse.new()
local success = http:http_no_body("DELETE", url, resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

-- A 200 response code indicates success (i.e. the request was sent and a response was received).
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
end

-- Sample JSON response:

-- {
--   "success": true
-- }

local bDeleted = jResp:bool_of("success")
print("Deleted: " .. tostring(bDeleted))

-- A failed response would look like this:

-- {
--   "success": false,
--   "message": "Product by \"id\" 8312 not found"
-- }