Publishing Content through API requests (Specifically Workfront Fusion) | Community
Skip to main content
New Participant
February 10, 2025
Solved

Publishing Content through API requests (Specifically Workfront Fusion)

  • February 10, 2025
  • 2 replies
  • 525 views

Hello,

 

I would like to know if there is a way to publish content (ie: content and/or experience fragments and assets) to the publisher instance via API calls. Our goal is to only allow publishing content via Workfront Fusion. If anyone could point me in the right direction, that would be highly appreciated.

 

Thank you! 

Best answer by Lokesh_Vajrala

Hi @bruce_fernandes 

 

You can write a servlet that exposes the end-point in AEM author that takes the payload and/or references to publish to publish instance. So that allows you to call the end-point from Workfront Fusion. 

 

For reference, check the below example: 

package com.example.core.servlets; import com.day.cq.replication.Agent; import com.day.cq.replication.ReplicationActionType; import com.day.cq.replication.Replicator; import com.day.cq.replication.ReplicationOptions; import com.day.cq.replication.ReplicationStatus; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.apache.sling.api.servlets.ServletResolverConstants; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import javax.servlet.Servlet; import javax.servlet.ServletException; import java.io.IOException; import java.util.Map; @Component( service = Servlet.class, property = { ServletResolverConstants.SLING_SERVLET_PATHS + "=/bin/publishcontent", ServletResolverConstants.SLING_SERVLET_METHODS + "=POST" } ) public class PublishContentServlet extends SlingAllMethodsServlet { @Reference private Replicator replicator; @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String contentPath = request.getParameter("contentPath"); if (contentPath == null || contentPath.isEmpty()) { response.setStatus(SlingHttpServletResponse.SC_BAD_REQUEST); response.getWriter().write("Error: Missing contentPath parameter."); return; } try { // Publish content replicator.replicate(request.getResourceResolver().adaptTo(Session.class), ReplicationActionType.ACTIVATE, contentPath); response.setStatus(SlingHttpServletResponse.SC_OK); response.getWriter().write("Content published successfully: " + contentPath); } catch (Exception e) { response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getWriter().write("Error publishing content: " + e.getMessage()); } } }

 

Thanks,

Lokesh

2 replies

ayush-anand
New Participant
February 11, 2025

Hi @bruce_fernandes ,

 

We need to write a servlet as @lokesh_vajrala  suggested. Since it should run only on the Author instance, we’ll need to expose this endpoint from Author to the third-party system.

There’s a similar thread on the AEM Community Portal about exposing a servlet from AEM Author to a third party. Sharing the link below—hope it helps!

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/right-way-to-expose-an-endpoint-servlet-from-aem-author-to-3rd/td-p/705401

 

Regards,

Ayush

Lokesh_Vajrala
Lokesh_VajralaAccepted solution
New Participant
February 10, 2025

Hi @bruce_fernandes 

 

You can write a servlet that exposes the end-point in AEM author that takes the payload and/or references to publish to publish instance. So that allows you to call the end-point from Workfront Fusion. 

 

For reference, check the below example: 

package com.example.core.servlets; import com.day.cq.replication.Agent; import com.day.cq.replication.ReplicationActionType; import com.day.cq.replication.Replicator; import com.day.cq.replication.ReplicationOptions; import com.day.cq.replication.ReplicationStatus; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.apache.sling.api.servlets.ServletResolverConstants; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import javax.servlet.Servlet; import javax.servlet.ServletException; import java.io.IOException; import java.util.Map; @Component( service = Servlet.class, property = { ServletResolverConstants.SLING_SERVLET_PATHS + "=/bin/publishcontent", ServletResolverConstants.SLING_SERVLET_METHODS + "=POST" } ) public class PublishContentServlet extends SlingAllMethodsServlet { @Reference private Replicator replicator; @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String contentPath = request.getParameter("contentPath"); if (contentPath == null || contentPath.isEmpty()) { response.setStatus(SlingHttpServletResponse.SC_BAD_REQUEST); response.getWriter().write("Error: Missing contentPath parameter."); return; } try { // Publish content replicator.replicate(request.getResourceResolver().adaptTo(Session.class), ReplicationActionType.ACTIVATE, contentPath); response.setStatus(SlingHttpServletResponse.SC_OK); response.getWriter().write("Content published successfully: " + contentPath); } catch (Exception e) { response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.getWriter().write("Error publishing content: " + e.getMessage()); } } }

 

Thanks,

Lokesh