Adding Bulk Users from a CSV file using Webscript

cancel
Showing results for 
Search instead for 
Did you mean: 
piyush48
Established Member

Adding Bulk Users from a CSV file using Webscript

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

3 Replies
EddieMay
Alfresco Employee

Re: Adding Bulk Users from a CSV file using Webscript

Hi @piyush48 ,

Have you looked at the documentation for bulk importing users on Enterprise & bulk importing into Community?

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
abhinavmishra14
Advanced

Re: Adding Bulk Users from a CSV file using Webscript

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...

https://hub.alfresco.com/t5/alfresco-content-services-forum/create-new-users-without-admin-rights/td...

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
sanjaybandhniya
Intermediate

Re: Adding Bulk Users from a CSV file using Webscript

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();	
}