Error when update user's department

When I tried to update user’s department through API using Update User’s Departments - Kintone Developer Program as reference, this error appeared

My code:

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.

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

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.

Tu, Chris

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

1 Like