Sample code for 30+ languages & platforms
Lianja

Shopware Delete Media

See more Shopware Examples

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

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

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

loHttp = createobject("CkHttp")

loHttp.Login = "api_username"
loHttp.Password = "api_key"
loHttp.BasicAuth = .T.

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

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

// Send a DELETE request with nothing in the request body.
loResp = createobject("CkHttpResponse")
llSuccess = loHttp.HttpNoBody("DELETE",lcUrl,loResp)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    release loResp
    return
endif

loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)

loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

// A 200 response code indicates success (i.e. the request was sent and a response was received).
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loResp.Header
    ? "Failed."
    release loHttp
    release loResp
    release loSbResponseBody
    release loJResp
    return
endif

// Sample JSON response:

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

llBDeleted = loJResp.BoolOf("success")
? "Deleted: " + str(llBDeleted)

// A failed response would look like this:

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


release loHttp
release loResp
release loSbResponseBody
release loJResp