Was this helpful?

This article describes how to batch delete entities in a collection. Batch deletes require the use of a query string in the request, which specifies a subset of entities to be deleted. For more information on queries, see Querying your data.

Currently, collections cannot be deleted; however, you can delete all of the entities from a collection.

Note: Although not shown in the API examples below, you need to provide a valid access token with each API call. See Authenticating users and application clients for details.

Batch deleting entities in a collection

Request Syntax

curl -X DELETE https://api.usergrid.com/<org>/<app>/<collection>/?ql=<query>

Parameters

Parameter Description
org Organization UUID or organization name
app Application UUID or application name
collection Collection UUID or collection name
query A query string that specifies the subset of entities to delete (for more information on queries, see Querying your data)

Example Request/Response

The following example will delete the first 5 entities in a collection.

Request:

curl -X DELETE https://api.usergrid.com/your-org/your-app/items/?ql="limit=5"

Response:

This example uses the iOS SDK.

SDK Method

(ApigeeClientResponse *)apiRequest: (NSString *)url operation:(NSString *)op data:(NSString *)opData

Properties

Parameter Description
url A fully-formed url in the following format:
https://api.usergrid.com/<org>/<app>/<collection>/?ql=

Note that you must include an empty '?ql=' query string at the end of the URL

op The HTTP method - in this case, 'DELETE'
opData No data is being sent, so the value is nil

Example Request/Response

The following example will delete the first 5 entities in a collection.

Request:

-(NSString*)deleteCollection {

	NSString *url = @"https://api.usergrid.com/your-org/your-app/items/?ql='limit=5'";
	NSString *op = @"DELETE";
	NSString *opData = nil;
	
	//we recommend you call ApigeeClient from your AppDelegate. 
	//for more information see the iOS SDK install guide: http://apigee.com/docs/app-services/content/installing-apigee-sdk-ios
	//create an instance of AppDelegate
	AppDelegate *appDelegate = (AppDelegate *)


Currently, batch deleting entities in a collection is not supported by the SDK for Android.

This example uses the JavaScript (HTML5) SDK.

SDK Method

request(options, callback)

Parameters

Parameter Description
options

A JSON-formatted object containing the following properties:

  • endpoint: the UUID or name of the collection to be emptied, appended by an empty query string in the format: <collection>/?ql=
  • method: the HTTP method for the request, in this case DELETE
callback Callback function to handle the API response

Example Request/Response

The following example will delete the first 5 entities in a collection.

Request:

//create the basic client object
var dataClient = new Apigee.Client({
	orgName:'your-org',
	appName:'your-app'
});

//options for the request
var options = {
	endpoint:"items",
	method:"DELETE",
	qs:{ql:'limit=5'}
}

dataClient.request(options,function (error, result) {

	if (error) { 
	    // Error
	} else { 
		// Success
	}

});    
				

Response:

The API will respond with 404 Resource Not Found.

SDK Method

delete_query <query_string>

Properties

Parameter Description
query_string A query string that specifies the entities to be deleted. Use an empty string ("") to delete all entities in the collection.

Example Request/Response

The following example will delete the first 5 entities in a collection.

Request:

#Create a client object
usergrid_api = 'https://api.usergrid.com'
organization = 'your-org'
application = 'your-app'

client = Usergrid::Application.new "#{usergrid_api}/#{organization}/#{application}"

begin
	client['item'].delete_query "limit=5"
rescue
	#fail
end
				

Response:

This example uses the Node.js module.

SDK Method

entity.destroy()

Parameters

Parameter Description
callback Callback function to handle the API response

Example Request/Response

The following example will delete the first 5 entities in a collection.

Request:

//create the basic client object
var dataClient = new Usergrid.client({
	orgName:'your-org',
	appName:'your-app'
});

//options for the request
var options = {
	endpoint:"items",
	method:"DELETE",
	qs:{ql:"limit=5"}
}

dataClient.request(options,function (error,result) {

	if (error) { 
	    // Error
	} else { 
		// Success
	}

});    	
				

Response:

{ action: 'delete',
  application: 'f34f4222-a166-11e2-a7f7-02e81adcf3d0',
  params: { ql: [ '' ] },
  path: '/tests',
  uri: 'http://api.usergrid.com/your-org/your-app/items',
  entities: 
   [ { uuid: '5eac800a-1a61-11e3-95b8-4f685c4bb3d6',
       type: 'item',
       name: 'milk',
       price: '3.25',
       created: 1378849125376,
       modified: 1378849125376,
       metadata: [Object] },
     { uuid: '5eb77c8a-1a61-11e3-aae6-3be70698d378',
       type: 'item',
       name: 'bread',
       price: '4.00',
       created: 1378849125448,
       modified: 1378849125448,
       metadata: [Object] } ],
  timestamp: 1378849137959,
  duration: 648,
  organization: 'your-org',
  applicationName: 'your-app' }
				

 

Add new comment

Provide your email address if you wish to be contacted offline about your comment.
We will not display your email address as part of your comment.

We'd love your feedback and perspective! Please be as specific as possible.
Type the characters you see in this picture. (verify using audio)

Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.