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.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.CHANNEL channel.
Example:
integer reqId := integer.getUnique();
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");
// Send request to find available managed objects
send request to com.apama.cumulocity.FindManagedObject.CHANNEL;
// Subscribe to com.apama.cumulocity.FindManagedObjectResponse.CHANNEL to listen
// for responses
monitor.subscribe(com.apama.cumulocity.FindManagedObjectResponse.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.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. |
Along with the above parameters, you can also provide other query parameters (such as pageSize) to be forwarded with the request to Cumulocity IoT.