Sample code for 30+ languages & platforms
Dart

Shopware Delete Media

See more Shopware Examples

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

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = 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', '6864');

  final url = 'https://my-shopware-shop.com/api/media/{\$id}';

  // Send a DELETE request with nothing in the request body.
  final resp = CkHttpResponse();
  try {
    http.httpNoBody('DELETE', url, resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final sbResponseBody = CkStringBuilder();
  resp.getBodySb(sbResponseBody);

  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  // A 200 response code indicates success (i.e. the request was sent and a response was received).
  final respStatusCode = resp.statusCode;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(resp.header);
    print('Failed.');
    return;
  }

  // Sample JSON response:

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

  final bDeleted = jResp.boolOf('success');
  print('Deleted: $bDeleted');

  // A failed response would look like this:

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