Implementing Bulk Delete Rest Api in Android Application

Hi, I need to make a bulk delete in one of my tables called TuckShop through my Android Application. I am sure I am just overlooking something. This is my AsyncTask class that runs in the background and tries to execute the REST Delete request:


private class DeleteEverythingFromTuckShop extends AsyncTask<Void,Void,Exception>{



 String API_URL = "https://api.backendless.com/CAD07C2B-DB80-7F6D-FFA6-48DEE0A95600/6C5DFBA6-502F-B26F-FA31-BC0AD90B0801/data/bulk/TuckShop?where=learnerBalanceAfter<1000";



 @Override
 protected void onPreExecute() {
 super.onPreExecute();
 //start showing progress dialog
 }



 @Override
 protected void onPostExecute(Exception e) {
 super.onPostExecute(e);
 //dismiss progress dialog



 if (e != null)
 {
 //show toast with exception message
 }



 }



 @Override
 protected Exception doInBackground(Void... params) {
 HttpURLConnection urlConnection = null;



 Exception exception = null;



 try {
 URL url = new URL(API_URL);
 urlConnection = (HttpURLConnection)url.openConnection();



 urlConnection.setRequestProperty( "application-id","CFD05C1B-AB80-7F6D-FFF6-49BEE0A96400" );
 urlConnection.setRequestProperty( "secret-key","6B9AFBA6-503F-B34F-FF21-BB0AD91B0910" );
 urlConnection.setRequestProperty( "application-type", "REST" );
 urlConnection.setRequestMethod("DELETE");
 urlConnection.connect();



 } catch (MalformedURLException e) {



 exception = e;
 } catch (IOException e) {



 exception = e;
 }finally {
 urlConnection.disconnect();
 }



 return exception;
 }



}

I hope you can help me sort this out. Using Backendless 4. Api keys in above example code is not the real application api keys.

Thanks

Johan

Also tried …where=learnerBalanceAfter%3C1000

Hi Johan,

Have you tested your where clause in console to make sure it returns any objects?

Regards,
Mark

Thanks for your prompt reply. I am totally new to REST so how do I do that?

I have 14 entries in the table. It returns 10

My Application runs without errors, but nothing happens. Also, why return only 10 if there is 14 that should be returned. All values for that field is 6 or less.

Changing the page size in Console returns all 14

Thus, my URL is fine. Somewhere in the Java/Android coding

Your java code doesn’t send anything to the server. Calling “connect()” is not enough. Read this or the java doc for more info: https://stackoverflow.com/questions/16122999/java-urlconnection-when-do-i-need-to-use-the-connect-method

Thank you very much!! I added one line : urlConnection.getInputStream(), before I called connect(). Everything works 100% now. Deleted all 14 records in that table directly from my code in Android.

One question…In the console I set the page size to 100 and offset to 0. Will that make a difference in BULK delete? Will it then only delete the first 100 objects?

http://support.backendless.com/public/attachments/1eed93edd19ae267877e30a3f25cb9d9.png</img>

http://support.backendless.com/public/attachments/074739a310529e2bb25d8148087d5249.png</img>

TuckShop is my table name and learnerBalanceAfter is my field. As Mark suggested, use the URL provided in the Console.

My code that now works for someone else having the same question. Thanks Mark!

I created 300 objects with a for loop. That call deleted all of them.

Thanks for your help Mark!