Using CumulocityRequestInterface in APAMA multi tenancy script to assign device to group

Hello there :slight_smile:

While using a multi tenancy apama script I want to assign a device to a device group via simple Post request:

https://{tenant}/inventory/managedObjects/{groupdID}/childAssets

body: { managedObject: { id: {deviceId}}

Using CumulocityRequestInterface produces the following error:

Finding device data from database failed : Some managedObjects don’t exist in database: '[ID [type=com_cumulocity_model_idtype_GId, value=461786690]]

The error is telling me that the managedObject of the device can not be found for the tenant, but it is available.
Also, If no managedObjects could be found, than the request should fail already for the groupId in the request url, but it doesnt.
If I use the same script for a single tenant apama engine, everything works fine.

Are there any restrictions on CumulocityRequestInterface while using multi tenancy or is there a better way to achieve a group device assignment?

View code:

var requestUrl := "https://{tenant}/inventory/managedObjects/{groupdID}/childAssets";
requestIface := CumulocityRequestInterface.connectToCumulocity();

		dictionary<string,any> params := new dictionary<string, any>;
		dictionary<string,any> paramssub := new dictionary<string,any>;
		paramssub.add("id", deviceId);
		params.add("managedObject", paramssub);
		Request request := requestIface.createRequest("POST", requestUrl, params);
		log request.toString() at INFO;
		request.execute(ResponseHandler().responseHandler);

Thanks in advance
Greets David

Hello :slight_smile:,

Not exactly sure what is causing your problem, but some pointers and further questions to try and diagnose this,

  • For invoking the Cumulocity API, we generally recommend the use of the GenericRequest interface, or other event-specific interfaces, rather than using the CumulocityRequestInterface: see the documentation at The Cumulocity Transport Connectivity Plug-in - Apama.
  • Are you aware of which tenant you are using to make the request from? With CumulocityRequestInterface, that request (from re-collection) will be coming from the parent tenant,
  • To have some more control over this, we’d recommend using the TenantSubscriptionNotifier API. See The Cumulocity Transport Connectivity Plug-in - Apama for more details.

Hopefully this gives you some more details to achieve your task, but let us know if you need more guidance!

Hello again,

thank you very much for your response. All things are clear now!

Greets David