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

**URL:** <https://community.cumulocity.com/t/using-cumulocityrequestinterface-in-apama-multi-tenancy-script-to-assign-device-to-group/9978>\
**Category:** Forum\
**Tags:** Streaming-Analytics-Apama, analytics, cumulocity\
**Created:** [February 26, 2025, 2:24pm UTC](https://community.cumulocity.com/t/using-cumulocityrequestinterface-in-apama-multi-tenancy-script-to-assign-device-to-group/9978 "2025-02-26T14:24:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MDT\_DBurger](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@MDT\_DBurger](https://community.cumulocity.com/u/MDT_DBurger)\
**Post date:** [February 26, 2025, 2:24pm UTC](https://community.cumulocity.com/t/using-cumulocityrequestinterface-in-apama-multi-tenancy-script-to-assign-device-to-group/9978/1 "2025-02-26T14:24:53Z")

</div>

Hello there 🙂

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Bevan\_Philip](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/bevan_philip/32/19444_2.png) [@Bevan\_Philip](https://community.cumulocity.com/u/Bevan_Philip)\
**Post date:** [February 28, 2025, 12:04pm UTC](https://community.cumulocity.com/t/using-cumulocityrequestinterface-in-apama-multi-tenancy-script-to-assign-device-to-group/9978/2 "2025-02-28T12:04:47Z")

</div>

Hello 🙂,

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](https://cumulocity.com/apama/docs/10.15/standard-connectivity-plugins/the-cumulocity-iot-transport-connectivity-plug-in/#invoking-other-parts-of-the-cumulocity-rest-api).
- 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](https://cumulocity.com/apama/docs/10.15/standard-connectivity-plugins/the-cumulocity-iot-transport-connectivity-plug-in/#working-with-multi-tenant-deployments) for more details.

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

---

<div class="post-metadata">

**Author:** ![MDT\_DBurger](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@MDT\_DBurger](https://community.cumulocity.com/u/MDT_DBurger)\
**Post date:** [March 3, 2025, 1:51pm UTC](https://community.cumulocity.com/t/using-cumulocityrequestinterface-in-apama-multi-tenancy-script-to-assign-device-to-group/9978/3 "2025-03-03T13:51:46Z")

</div>

Hello again,

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

Greets David
