Xbase++
Xbase++
ShopwareDelete Product
See more Shopware Examples
Deletes a product in Shopware.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL cUrl
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL nBDeleted
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oHttp:Login := "api_username"
oHttp:Password := "api_key"
oHttp:BasicAuth := 1
// The id of the product is appended to the path part of the URL.
oHttp:SetUrlVar("id", "8312")
cUrl := "https://my-shopware-shop.com/api/articles/{$id}"
// Send a DELETE request with nothing in the request body.
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("DELETE", cUrl, oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
RETURN
ENDIF
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
// A 200 response code indicates success (i.e. the request was sent and a response was received).
nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oResp:Header
? "Failed."
oHttp:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
ENDIF
// Sample JSON response:
// {
// "success": true
// }
nBDeleted := oJResp:BoolOf("success")
? "Deleted: " + Str(nBDeleted)
// A failed response would look like this:
// {
// "success": false,
// "message": "Product by \"id\" 8312 not found"
// }
oHttp:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()