# Error when update user's department

**URL:** <https://forum.kintone.dev/t/error-when-update-users-department/254>\
**Category:** General\
**Created:** [February 20, 2022, 8:11am UTC](https://forum.kintone.dev/t/error-when-update-users-department/254 "2022-02-20T08:11:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [February 20, 2022, 8:11am UTC](https://forum.kintone.dev/t/error-when-update-users-department/254/1 "2022-02-20T08:11:10Z")

</div>

When I tried to update user’s department through API using [Update User’s Departments - Kintone Developer Program](https://kintone.dev/en/docs/common/user-api/departments/update-users-departments/) as reference, this error appeared

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/kintone/original/1X/794da6db1ac58a0e89c8ec0a9a647c07d067d0d7.png)

My code:

```javascript
var body = {
    'code': 'my_user_code',
    'organizations': [
    {
        'orgCode': 'department_code',
        'titleCode': null
    }
    ]
};

kintone.api(kintone.api.url('/v1/userOrganizations', true), 'PUT', body, function(resp) {
    // success
    console.log(resp);
}, function(error) {
    // error
    console.log(error);
});

```

Note that `my_user_code` and `department_code` is correct as I used correctly in other APIs and I have admin permission.

i also try to update using this body ( mean remove all user’s department) but the same error occurred.

```javascript
    var body = {
      'code': 'my_user_code',
      'organizations': [
      ]
    };

```

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [February 21, 2022, 7:07pm UTC](https://forum.kintone.dev/t/error-when-update-users-department/254/2 "2022-02-21T19:07:32Z")

</div>

Hello Tu

I got the same error when I tried the script on the page, but when I added  
**"userOrganizations"**  
to the script like below, it updated successfully.

```
var body = {
 "userOrganizations" : [
  {
  'code': 'my_user_code',
  'organizations': [
    {
      'orgCode': 'department_code',
    }
  ]
}
]
};

```

I hope this helps.

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [February 24, 2022, 10:24am UTC](https://forum.kintone.dev/t/error-when-update-users-department/254/3 "2022-02-24T10:24:26Z")

</div>

Tu, Chris

**userOrganizations** &nbsp;was missing from the parameters and sample code in the Docs.  
The Docs have now been updated. Thanks for pointing this out!
