Avatar

Add users to department

David Mowry

Through the User API, I can get users, I can get departments, but I can't seem to find a way to add a user to a department. Is this possible and i'm just missing something?

Follow 3 followers
0

1 comment

Avatar
Sean Tachibana 0 votes
I did not find an English help page for this matter but I wrote a sample code based on the Japanese help page.

 

// Generate CSV file (content to make UserA belong to the organization codes "test" and "test2". The position code is set to empty.)

blob = new Blob(["UserA,test,,test2,"], {type:"text\/plain"});

var formData = new FormData();

formData.append("__REQUEST_TOKEN__", kintone.getRequestToken());

formData.append("file", blob , "test.csv");




xmlHttp = new XMLHttpRequest();

xmlHttp.open("POST", encodeURI('/v1/file.json'), false);

xmlHttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');

xmlHttp.responseType = 'multipart/form-data';

xmlHttp.send(formData);

var key = JSON.parse(xmlHttp.responseText).fileKey;

console.log(key);




// Using the CSV file, execute the user's Organization Import API

var prm = {

'fileKey' : key

};




kintone.api(

'/v1/csv/userOrganizations',

'POST',

prm,

function(event){

console.log(event);

},

function(err){

console.log(err);

}

);

 

Please note that only CSV format is supported, and currently, the JSON format is not supported.
Also, as with the standard function, if existing organizations are not included, they will be removed from the existing organization.

 

Hopefully, this helps.
0
Comment actions Permalink