« Back to Web Services

Web Service samples

Introduction #

When initially installing Liferay in an environment without a LDAP, it often takes time to enter master data such as user and organization from Liferay's Control Panel page. In such a circumstance, it is often easier to upload a csv file in bulk from a command line. Liferay offers a web service interface to make this possible. This page will try to present an actually working program to add users and organization to Liferay v6.0.5 from a batch file. Note, that this is just a sample program written so that it would be easier to read. In actual production environment, it is recommended to modify the sample source code to make it more effiecient.

Obtaining the Sample Web Service Tools #

Sample tool to add users may be downloaded from the attachment to this page. Just download the file and extract it to some folder to use it.

Caution: The tool will not work with Liferay v5.x because it has a different web service interface

Using the tool #

First, the tool is written is Java so it requires Java to be installed. Second, the tool requires Liferay to be running and requires Liferay's administrative credentials (aka admin user/password).

Open up the ws-settings.properties from using a text editor and edit the username, password, host, and port fields with values from your Liferay installation. Example:

username=test
password=test
host=http://localhost
port=8080

Retrieving User Information #

If you are using Liferay's bundled download with the demo pages, try retrieving user data using the sample batch command (Linux users would have to create a .sh script): Edit the userGetSample.bat file and comment out row 3 and uncomment row 9.

echo off
rem get user information by screen name
rem userGet.bat -output users.csv -type screen -value "10131,test"

rem get user information by userid
rem userGet.bat -output users.csv -type userid -value 10134

rem get user information by email
userGet.bat -output users.csv -type email -value "10131,test@liferay.com"

Executing this script will create a csv file users.csv in the local folder. This file should contain user data for the test user if the program was able to connect properly to Liferay. If there was an error, it should display in the console.

Adding User Information #

To bulk add users, create a csv file with user information. The tools uses format matching Liferay's web service interface which unfortunately has different interface format for getting user information and adding user information. The format used to add users is provided in the data\Template folder - usersTemplate.xls. A sample of a csv file is provided in the \data folder. Fill out the necessary information for each user to add. Edit the usersImport.bat file to point to the csv file.

java jp.co.ogis.liferay.util.UsersImport data\users.csv

Execute this batch file and users will be added with information provided in the csv file with other default settings provided in the portal.properties and portal-ext.properties files. Login as an administrator to check if users have been added.

3 Attachments
49416 Views
Average (3 Votes)
The average rating is 5.0 stars out of 5.
Comments
Threaded Replies Author Date
Thank you for great information and sample... Tetsuya Zama July 19, 2011 11:16 PM
hi , I am trying to add bulk users in liferay... Shripad Bharde October 4, 2011 2:07 AM
Hi, The link to the sample code under... Ivano Carrara October 24, 2011 2:35 PM
The sample code is also available as an... Ken Barron December 20, 2011 5:05 AM
Thanks very much for making this available! ... Ken Barron December 20, 2011 6:48 AM
help.... it doesn't work in my laptop. I've... Iseng Dong April 25, 2012 3:27 AM
did you finally get the answers to your... austen xia July 5, 2013 1:35 AM
Hi i do get the same error ... sandeep tripathi May 28, 2012 2:23 AM
I want to create similar web service to... urman parikh August 8, 2012 2:05 AM
Hi.. Thanks for this useful tool.. I have tried... Jo Cern October 14, 2013 4:01 PM
Hi, Some time ago I wrote an article for import... Antonio Musarra April 16, 2014 3:01 PM

Thank you for great information and sample codes!
This is that I've been looking for.
Posted on 7/19/11 11:16 PM.
hi ,

I am trying to add bulk users in liferay using web service 'liferay-wstools_20110119' (http://www.liferay.com/community/wiki/-/wiki/Main/Web+Service+samples)
but when I try to load users with already present users.csv I get exception


Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateCo­nverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)­
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(Abstract­FlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListe­ner.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at com.liferay.portal.dao.orm.hibernate.SessionImpl.flush(SessionImpl.java:108)
... 92 more
Caused by: java.sql.BatchUpdateException: Incorrect string value: '\xE3\x82\x88\xE3\x81\x86...' for column 'greeting' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:125­7)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPrepared­Statement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 98 more


is there any problem in given sample user.csv or do you have sample user.csv which can add users using web service .



Thanks & Regards ,

Shripad Bharde
Posted on 10/4/11 2:07 AM.
Hi,

The link to the sample code under "Obtaining the Sample Web Service Tool" is broken ...
Posted on 10/24/11 2:35 PM.
The sample code is also available as an attachment to this article.
Posted on 12/20/11 5:05 AM in reply to Ivano Carrara.
Thanks very much for making this available! Saved me a day of coding, exactly what I need.
P.S. one tip, make sure you have tunnel-web installed as a webapp otherwise the servcice calls will not work.
Posted on 12/20/11 6:48 AM.
help.... it doesn't work in my laptop.

I've tried at Liferay 6.1. I could see the process that the datas are being moved. But, when I took a look at user and organization menu and also in my mysql, there was nothing. It is still the default data.

and, I also have tried in Liferay 6.0. In the process, it says "skipped". The system skipped all of the row.

what should I do? thanks in advance emoticon
Posted on 4/25/12 3:27 AM.
Hi
i do get the same error
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
is there any other setting which we need to do .
thanks and regards
Sandeep
Posted on 5/28/12 2:23 AM.
I want to create similar web service to associate site template to public/private pages to an organization when organization is added.

So when i add organization it's site should be created and its public/private page should have site templete.

can any one help.
Posted on 8/8/12 2:05 AM.
did you finally get the answers to your question? I got the same error
Posted on 7/5/13 1:35 AM in reply to Iseng Dong.
Hi..
Thanks for this useful tool..
I have tried to get it to work (user import) with the 6.2s interface by editing the UserInfo.java and UserImport. java accordingly.. no luck so far get the user table updated but with a message unknown element when running the BAT file.. in the logs on the server I have this error
17:48:31,744 ERROR [http-bio-8080-exec-4][UserServiceSoap:92] com.liferay.portal.DuplicateUserEmailAddressException
edited userimport.java with >> UserSoap usoap= soap.addUser(userInfo.getcompanyId(),userInfo.getAutoPassword(),userInfo.getPass­word1(),userInfo.getPassword2(),userInfo.getAutoScreenName(),userInfo.getScreenN­ame(),userInfo.getEmailAddress(),userInfo.getFacebookId(),userInfo.getOpenId(),u­serInfo.getLocale(),userInfo.getFirstName(),userInfo.getMiddleName(),userInfo.ge­tLastName(),userInfo.getPrefixId(),userInfo.getSuffixId(),userInfo.getMale(),use­rInfo.getBirthdayMonth(),userInfo.getBirthdayDay(),userInfo.getBirthdayYear(),us­erInfo.getJobTitle(),userInfo.getGroupIds(),userInfo.getOrganizationIds(),userIn­fo.getRoleIds(),userInfo.getUserGroupIds(),userInfo.getSendEmail(),serviceContex­t);

And also the UserInfo.java with the corresponding values... I am obviously missing something... a little help or hint in the right direction would be much appreciated..
Cheers
Posted on 10/14/13 4:01 PM.
Hi,
Some time ago I wrote an article for import users from an excel sheet using web services liferay. http://www.dontesta.it/blog/blog-2/cms/liferay/liferay-web-services-come-importa­re-utenti/ The source repository at https://github.com/amusarra/ImportUsersLiferayViaWS

Bye,
Antonio.
Posted on 4/16/14 3:01 PM.