Querying for managed objects
To search for a managed object or a collection of managed objects, send the com.apama.cumulocity.FindManagedObject event to Cumulocity IoT, with a unique reqId to the com.apama.cumulocity.FindManagedObject.SEND_CHANNEL channel.
The transport will then respond with zero or more com.apama.cumulocity.FindManagedObjectResponse events and then one com.apama.cumulocity.FindManagedObjectResponseAck event on the com.apama.cumulocity.FindManagedObjectResponse.SUBSCRIBE_CHANNEL channel.
Example:
integer reqId := com.apama.cumulocity.Util.generateReqId();
com.apama.cumulocity.FindManagedObject request :=
new com.apama.cumulocity.FindManagedObject;
request.reqId := reqId;
// Optionally provide the 'id' of the managed object
//request.deviceId := "<DEVICE_ID>";
// Filter based on fragmentType
request.params.add("fragmentType", "c8y_IsDevice");
// Subscribe to com.apama.cumulocity.FindManagedObjectResponse.SUBSCRIBE_CHANNEL to
// listen for responses
monitor.subscribe(com.apama.cumulocity.FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
// Listen for responses based on reqId
on all com.apama.cumulocity.FindManagedObjectResponse(reqId=reqId) as response
// Avoid listener leaks by terminating the listener on completion of the request
and not com.apama.cumulocity.FindManagedObjectResponseAck(reqId=reqId)
{
log "Received ManagedObject " + response.toString() at INFO;
}
// Listen for com.apama.cumulocity.FindManagedObjectResponseAck,
// this indicates that all responses have been received
on com.apama.cumulocity.FindManagedObjectResponseAck(reqId=reqId)
as requestCompleted
{
log "Received all ManagedObject(s) for request "
+ requestCompleted.reqId.toString() at INFO;
// Request is completed and we can unsubscribe from this channel
monitor.unsubscribe(com.apama.cumulocity.FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
}
// Send request to find available managed objects
send request to com.apama.cumulocity.FindManagedObject.SEND_CHANNEL;
Supported query parameters
You can provide the following query parameters with the request:
Parameter | Description |
deviceId | Search for a managed object based on deviceId. When deviceId is populated in a FindManagedObject request, all the query parameters listed below are ignored. |
fragmentType | Search for managed objects based on the fragment type. |
type | Search for managed objects based on the type. |
owner | Search for managed objects based on the owner. |
text | Search for managed objects based on the text. |
childAssetId | Search for managed objects based on the asset identifier of the child. |
childDeviceId | Search for managed objects based on the device identifier of the child. |
ids | Search for managed objects based a comma-separated list of device identifiers. |
pageSize | Indicates how many entries of the collection are to be retrieved from Cumulocity IoT. This is a batching parameter for getting multiple responses from Cumulocity IoT. A larger pageSize does fewer requests to Cumulocity IoT to retrieve all the managed objects, but each request is larger. By default, 1000 managed objects are in each page and there is an upper limit of 2000. |
currentPage | Retrieve a specific page of results for the given pageSize. If currentPage is set, then only a single page is requested. If currentPage is not set (default), all the pages are requested. |
For a comprehensive list of allowed query parameters, see the Cumulocity IoT OpenAPI Specification at
https://cumulocity.com/api/#operation/getManagedObjectCollectionResource.
Query result paging
Cumulocity IoT queries support paging of data for requesting a specific range of the responses received. For more information, see
Paging Cumulocity IoT queries.