Sample code for 30+ languages & platforms
Android™

ShopwareDelete Product

See more Shopware Examples

Deletes a product in Shopware.

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

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

    CkHttp http = new CkHttp();

    http.put_Login("api_username");
    http.put_Password("api_key");
    http.put_BasicAuth(true);

    // The id of the product is appended to the path part of the URL.
    http.SetUrlVar("id","8312");

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

    // Send a DELETE request with nothing in the request body.
    CkHttpResponse resp = new CkHttpResponse();
    success = http.HttpNoBody("DELETE",url,resp);
    if (success == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    resp.GetBodySb(sbResponseBody);

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    Log.i(TAG, "Response Body:");
    Log.i(TAG, jResp.emit());

    // A 200 response code indicates success (i.e. the request was sent and a response was received).
    int respStatusCode = resp.get_StatusCode();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, resp.header());
        Log.i(TAG, "Failed.");
        return;
        }

    // Sample JSON response:

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

    boolean bDeleted = jResp.BoolOf("success");
    Log.i(TAG, "Deleted: " + String.valueOf(bDeleted));

    // A failed response would look like this:

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

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}