Sample code for 30+ languages & platforms
React Native

Shopware Delete Media

See more Shopware Examples

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

Chilkat React Native Downloads

React Native
import { Http, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'

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

  const http = new Http();

  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');

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

  // Send a DELETE request with nothing in the request body.
  const resp = new HttpResponse();
  try {
    await http.httpNoBodyAsync('DELETE', url, resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  const sbResponseBody = new StringBuilder();
  resp.getBodySb(sbResponseBody);

  const jResp = new JsonObject();
  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).
  const 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
  // }

  const bDeleted = jResp.boolOf('success');
  console.log(`Deleted: ${bDeleted}`);

  // A failed response would look like this:

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