# Cumulocity @c8y/client problem in InventoryService update() method

**URL:** <https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995>\
**Category:** Forum\
**Tags:** web-development, c8y-webSDK, cumulocity-edge\
**Created:** [February 6, 2025, 1:54pm UTC](https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995 "2025-02-06T13:54:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidelh](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@davidelh](https://community.cumulocity.com/u/davidelh)\
**Post date:** [February 6, 2025, 1:54pm UTC](https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995/1 "2025-02-06T13:54:39Z")

</div>

#### _ **Product/components** used and **version/fix** level:_

Cumulocity Web SDK - @c8y/client v1021.31.4 (latest)

#### _Detailed explanation of the problem:_

Hi, I am currently using the c8y client to develop a custom widget plugin for Cumulocity. In particular, I need to update a managed object, so I am using the update() method of the InventoryService ([InventoryService | Cumulocity Web SDK - v1023.4.8](https://resources.cumulocity.com/documentation/websdk/client/classes/InventoryService.html#update)).  
This method takes only a Partial\<IManagedObject\> as input, but does not have any reference to the object id. I tried to include the id in the input but the request is not recognized by Cumulocity. In fact, the PUT api to update objects takes the id as path variable (inventory/managedObject/:id).

#### _Error messages / **full error** message screenshot / **log** file:_

I received a 405 error saying “Method not allowed”. I can see in logs that the endpoint called is PUT inventory/managedObject (without the id).  
Is this a bug of the InventoryService or am I doing something wrong?

#### _Question related to a **free trial** , or to a **production (customer)** instance?_

Production

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [February 6, 2025, 2:11pm UTC](https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995/2 "2025-02-06T14:11:05Z")

</div>

Hi @davidelh,

it would help if you could provide a code snippet of what you are doing.

Something like this should work:

```typescript
const partialUpdateObject: Partial<IManagedObject> = {
   id: '123456'
   customFragment: 'Changed data',
   name: 'Name'
 };

 (async () => {
   const {data, res} = await inventoryService.update(partialUpdateObject);
 })();

```

The id is taken from the object you are passing in.  
The types could be improved here as the id is a required attribute of the object you are passing in…

Regards,  
Tristan

---

<div class="post-metadata">

**Author:** ![davidelh](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@davidelh](https://community.cumulocity.com/u/davidelh)\
**Post date:** [February 6, 2025, 3:24pm UTC](https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995/3 "2025-02-06T15:24:32Z")

</div>

Hi @Tristan_Bastian ,

Here is my snippet, it is very similar to yours (I started from the official documentation). I made sure that asset\_id is always defined:

```auto
async updateAsset(asset_id: string) {
    try {      
      const partialUpdateObject: Partial<IManagedObject> = {
        id: asset_id,
        myProperty: 'new property value'
      };
      const {data, res} = await this.inventoryService.update(partialUpdateObject);
      console.log('Asset updated successfully');
    } catch (error) {
      console.error('Error updating asset: ', error);
    }
}

```

From the documentation, it does not seem that the id is a required attribute of the object ([InventoryService | Cumulocity Web SDK - v1021.31.4](https://resources.cumulocity.com/documentation/websdk/client/classes/InventoryService.html#update)).

Here is a screen capture of the error log:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/3/d/3df7f39dab99c86e0b3699429082cdc4fa7e0276.png)

As you can see, no id is included in the url path.

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [February 6, 2025, 3:49pm UTC](https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995/4 "2025-02-06T15:49:57Z")

</div>

Hi @davidelh,

Only guess I have is, that you are not actually passing an `asset_id` when calling `updateAsset`.  
Can you log the `partialUpdateObject` object before sending it? Like e.g. this:

```typescript
async updateAsset(asset_id: string) {
    try {      
      const partialUpdateObject: Partial<IManagedObject> = {
        id: asset_id,
        myProperty: 'new property value'
      };
      console.log(JSON.stringify(partialUpdateObject));
      const {data, res} = await this.inventoryService.update(partialUpdateObject);
      console.log('Asset updated successfully');
    } catch (error) {
      console.error('Error updating asset: ', error);
    }
}

```

Regards,  
Tristan

---

<div class="post-metadata">

**Author:** ![davidelh](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@davidelh](https://community.cumulocity.com/u/davidelh)\
**Post date:** [February 6, 2025, 5:20pm UTC](https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995/5 "2025-02-06T17:20:38Z")

</div>

Hi @Tristan_Bastian ,

Yes, it was a problem with the asset\_id that for some reason was passed as undefined to the updateAsset method. Now I can correctly see the id in the partialUpdateObject and the update() method works.

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [February 7, 2025, 5:20pm UTC](https://community.cumulocity.com/t/cumulocity-c8y-client-problem-in-inventoryservice-update-method/7995/6 "2025-02-07T17:20:48Z")

</div>

Closed on February 7, 2025, 5:20pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
