Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Import users from excel or csv file in AEM

Avatar

Level 2

Hi Team,

We are trying to import the users from the excel or csv file to  specified group in AEM on AEM 6.4, I tried the steps mentioned in Adobe Experience Manager Help | Creating a custom Excel Service for Adobe Experience Manager but no luck , any pointers or alternate way to achieve it on AEM 6.4 ??

1 Accepted Solution

Avatar

Correct answer by
Level 10

This use case is very possible and be easy to do. You would need to write a custom AEM serviec that can read Excel. You can use the Java EXCEL API to do so. See this older artilce:

Scott's Digital Community: Creating a custom Excel Service for Adobe Experience Manager

Read all of the user data from the EXCEL doc, place in a Java collection object and then iterate through the collection and use the USER MANAGER API to create the users.

View solution in original post

7 Replies

Avatar

Level 1

Did you try to create users using the UserManager API? There is an example on Adobe help site. I am just copy-pasting the snippet here, please go throuhg the complete example to understand better.

1. Create a group

Group group=userManager.createGroup(groupName,new SimplePrincipal(groupName),"/home/groups/test");

Value value=adminSession.getValueFactory().createValue("Sample Group", PropertyType.STRING);

group.setProperty("./profile/givenName", value);

value=adminSession.getValueFactory().createValue("Test Group", PropertyType.STRING);

group.setProperty("./profile/aboutMe", value);

value=adminSession.getValueFactory().createValue("abc@gmail.com", PropertyType.STRING);

group.setProperty("./profile/email", value); 

2. Create the user(s)

You can read the csv file, iterate the rows and create the users

User user=userManager.createUser(userName, password,new SimplePrincipal(userName),"/home/users/test");

Value value=adminSession.getValueFactory().createValue("Issac", PropertyType.STRING);

user.setProperty("./profile/familyName", value);

value=adminSession.getValueFactory().createValue("Albin", PropertyType.STRING);

user.setProperty("./profile/givenName", value);

value=adminSession.getValueFactory().createValue("Test User", PropertyType.STRING);

user.setProperty("./profile/aboutMe", value);

value=adminSession.getValueFactory().createValue("albin@gmail.com", PropertyType.STRING);

user.setProperty("./profile/email", value);

3. Add the user to the group

Group group = (Group)(userManager.getAuthorizable(groupName));

group.addMember(userManager.getAuthorizable(userName));

Avatar

Level 2

Thanks for your quick response.

Yes I tried the above link and able to add the user as mentioned, but I am looking for reading the users from the excel or csv file and adding to group.

Avatar

Level 10

what error do you get in the article you shared? It should work fine, just use maven archetype 13+ and use the same code or if you want to convert the same to R6, that's also possible.

Avatar

Level 7

Hi,

you could try to use a cURL command in order to import users into AEM.

You need to run something like the following command:

curl -u admin:admin -FcreateUser= -FauthorizableId=$UserNameReadFromCSV -Frep:password=$PasswordReadFromCSV http://localhost:4502/libs/granite/security/post/authorizables 

Try as described here: cq5 - how import users to AEM/CQ from excel - Stack Overflow

Let us know.

Thanks,

Antonio

Avatar

Correct answer by
Level 10

This use case is very possible and be easy to do. You would need to write a custom AEM serviec that can read Excel. You can use the Java EXCEL API to do so. See this older artilce:

Scott's Digital Community: Creating a custom Excel Service for Adobe Experience Manager

Read all of the user data from the EXCEL doc, place in a Java collection object and then iterate through the collection and use the USER MANAGER API to create the users.

Avatar

Level 1

May be I am late to the party but I have been working on this requirement and created a utility in the AEM for the same.

This utility allows the users to upload an excel file with the user details and creates users in the AEM to the desired group automatically.

https://aem.redquark.org/2019/05/create-users-in-aem-from-excel-file.html

You can see the code for the same at my GitHub. I hope this helps someone.

https://github.com/ani03sha/BulkUserCreation