—Rate this article—
 

Deleting Collections

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:

{
  "action" : "delete",
  "application" : "f34f4222-a166-11e2-a7f7-02e81adcf3d0",
  "params" : {
    "ql" : [ "" ]
  },
  "path" : "/items",
  "uri" : "http://api.usergrid.com/your-org/your-app/items",
  "entities" : [ {
    "uuid" : "53fe3700-0abe-11e3-b1f7-1bd100b8059e",
    "type" : "item",
    "name" : "milk",
    "price" : "3.25",
    "created" : 1377129832047,
    "modified" : 1377129832047,
    "metadata" : {
      "path" : "/items/53fe3700-0abe-11e3-b1f7-1bd100b8059e"
    },
    "name" : "milk"
  }, {
    "uuid" : "5ae1fa7a-0abe-11e3-89ab-6be0003c809b",
    "type" : "item",
    "name" : "bread",
    "price" : "4.00",
    "created" : 1377129843607,
    "modified" : 1377129843607,
    "metadata" : {
      "path" : "/items/5ae1fa7a-0abe-11e3-89ab-6be0003c809b"
    },
    "name" : "bread"
  } ],
  "timestamp" : 1378848117272,
  "duration" : 12275,
  "organization" : "your-org",
  "applicationName" : "your-app"
}

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 *)[[UIApplication sharedApplication] delegate];
	
	//call createEntity to initiate the API call
	ApigeeClientResponse *response = [appDelegate.dataClient apiRequest: url operation: op data: opData];
	
	@try {
	    //success
	}
	@catch (NSException * e) {
	    //fail
	}

}
				

Response:

{
  "action" : "delete",
  "application" : "f34f4222-a166-11e2-a7f7-02e81adcf3d0",
  "params" : {
    "ql" : [ "" ]
  },
  "path" : "/items",
  "uri" : "http://api.usergrid.com/your-org/your-app/items",
  "entities" : [ {
    "uuid" : "53fe3700-0abe-11e3-b1f7-1bd100b8059e",
    "type" : "item",
    "name" : "milk",
    "price" : "3.25",
    "created" : 1377129832047,
    "modified" : 1377129832047,
    "metadata" : {
      "path" : "/items/53fe3700-0abe-11e3-b1f7-1bd100b8059e"
    },
    "name" : "milk"
  }, {
    "uuid" : "5ae1fa7a-0abe-11e3-89ab-6be0003c809b",
    "type" : "item",
    "name" : "bread",
    "price" : "4.00",
    "created" : 1377129843607,
    "modified" : 1377129843607,
    "metadata" : {
      "path" : "/items/5ae1fa7a-0abe-11e3-89ab-6be0003c809b"
    },
    "name" : "bread"
  } ],
  "timestamp" : 1378848117272,
  "duration" : 12275,
  "organization" : "your-org",
  "applicationName" : "your-app"
}


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:

{
  "action" : "delete",
  "application" : "f34f4222-a166-11e2-a7f7-02e81adcf3d0",
  "params" : {
    "ql" : [ "" ]
  },
  "path" : "/items",
  "uri" : "http://api.usergrid.com/your-org/your-app/items",
  "entities" : [ {
    "uuid" : "53fe3700-0abe-11e3-b1f7-1bd100b8059e",
    "type" : "item",
    "name" : "milk",
    "price" : "3.25",
    "created" : 1377129832047,
    "modified" : 1377129832047,
    "metadata" : {
      "path" : "/items/53fe3700-0abe-11e3-b1f7-1bd100b8059e"
    },
    "name" : "milk"
  }, {
    "uuid" : "5ae1fa7a-0abe-11e3-89ab-6be0003c809b",
    "type" : "item",
    "name" : "bread",
    "price" : "4.00",
    "created" : 1377129843607,
    "modified" : 1377129843607,
    "metadata" : {
      "path" : "/items/5ae1fa7a-0abe-11e3-89ab-6be0003c809b"
    },
    "name" : "bread"
  } ],
  "timestamp" : 1378848117272,
  "duration" : 12275,
  "organization" : "your-org",
  "applicationName" : "your-app"
}

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' }
				

 

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)