Hi All,
I have a .csv file of Users with me which i want to add using webscript. Could anyone please guide me with this how i can use webscript to read .csv file and create user from it.
Thanks,
Piyush
Hi @piyush48 ,
Have you looked at the documentation for bulk importing users on Enterprise & bulk importing into Community?
HTH,
There is a way to upload users in bulk using CSV via share admin tools
[EDIT:] Look at this documentation share by @EddieMay : https://docs.alfresco.com/6.2/tasks/admintools-upload-users.html
You can also use this webscript to upload the users in bulk:
POST /alfresco/service/api/people/upload
Example: (POST) http://127.0.0.1:8080/alfresco/service/api/people/upload
Download Bulk load CSV Template from here: GET /alfresco/service/api/people/upload?format=csv Example: (GET) http://127.0.0.1:8080/alfresco/service/api/people/upload?format=csv
This is the webscript definition for your reference:
org/alfresco/repository/person/user-csv-upload.post.desc.xml <webscript> <shortname>Create Users by using uploading of a CSV</shortname> <description> Allows an administrator to upload a CSV describing new users, who will then have accounts created for them. Note - if the CSV is uploaded OK, but there was a problem with the contents or creating the users, you will receive a 200 status code along with details of the problem. </description> <url>/api/people/upload</url> <format default="json"></format> <authentication>admin</authentication> <lifecycle>internal</lifecycle> <!-- Transactions are handled inside the webscript itself --> <transaction>none</transaction> <lifecycle>limited_support</lifecycle> </webscript>
If you have something very specific requirement for bulk loading users via CSV, which can't be met using the above given approaches, then you can choose to create your own webcript.
Look at these solutions for further reference to a custom bulk load users webscript: https://hub.alfresco.com/t5/alfresco-content-services-forum/i-want-to-add-bulk-users-to-groups-and-p...
Read CSV and create user:
function isCSVDoc(document){ var isCSV = document.getMimetype(); return ((isCSV=="text/csv") ? "true" : "false"); } function getCSVLines(){ var csvFile = companyhome.childByNamePath("xxx.csv"); if(isCSVDoc(csvFile)=="true"){ csvDoc = document; var csvContent = csvDoc.getContent(); var lines = csvContent.split("\n"); logger.debug("=============THIS IS CONTENT========="+lines[1]); return lines; } else { return null; } } function main() { var csvLines = getCSVLines(); if(csvLines != null) { var nodeRefArray = new Array(); for(var i=1; i<csvLines.length; i++) { var column = csvLines[i].split(","); var userName=column[1]; var email=column[2]; var firstName=column[3]; var lastName=column[4]; var password=column[5].trim(); logger.debug(groupName +":"+userName +":"+email+":"+firstName+":"+lastName+":"+password); var newUser = people.createPerson(userName, firstName, lastName, email, password, true); } } } if(document){ main(); }
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.