How to create content programatically

Jamie Sammons, modified 3 Years ago. New Member Posts: 7 Join Date: 10/8/19 Recent Posts

Hi everyone,

I need to programatically create content (both pages based on template and web contents) on my Liferay 7.4 instance.

Basically I need to implement in Liferay a scheduled task which every night will fetch data from an external database and:

  1. Create a web content by filling the fields of the underlying structure
  2. Create a page using a specific template (it could be both a content page or a widget page) 

Is this possible?

Can you suggest me the best way to do that and/or provide some hints about which Liferay API I should use?

 

Best regards,

Pietro

thumbnail
Mohammed Yasin, modified 3 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts

Hi ,

You can below API for creating Web Content and Page

//WebContent       
_journalArticleLocalService.addArticle(externalReferenceCode, userId, groupId, folderId, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, serviceContext);

//Pages
 _layoutLocalService.addLayout(userId, groupId, privateLayout, parentLayoutId, name, title, description, type, hidden, friendlyURL, serviceContext)