Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

How to publish an asset/page programmatically in AEMaaCS?

Avatar

Level 9

Team - In the past, we used Replicator (com.day.cq.replication.Replicator) to activate pages programmatically. Currently, I'm trying to publish assets and pages in a custom workflow in AEMaacS. 

 

AEMaaCS does not use the replication agents used in previous versions of AEM. As I understand it, content in AEM Cloud Service is replicated using Sling Content Distribution to a pipeline service that is not part of AEM.

 

Could you please tell me what APIs should be used to call appropriate distributions to publish a specific asset?

 
 
1 Accepted Solution

Avatar

Correct answer by
Level 6

@Mario248 

In AEM Cloud as well you can use Replicator API to activate resources. In cloud you don't need to provide any replication agent via ReplicationOptions. Replicator API picks the only active agent in AEM cloud which is "publish" agent.

So below code should work as its working for me in my workflow process.

@Reference
private Replicator replicator;
replicator.replicate(session, ReplicationActionType.ACTIVATE, assetPath);

View solution in original post

4 Replies

Avatar

Correct answer by
Level 6

@Mario248 

In AEM Cloud as well you can use Replicator API to activate resources. In cloud you don't need to provide any replication agent via ReplicationOptions. Replicator API picks the only active agent in AEM cloud which is "publish" agent.

So below code should work as its working for me in my workflow process.

@Reference
private Replicator replicator;
replicator.replicate(session, ReplicationActionType.ACTIVATE, assetPath);

Avatar

Level 9

Thanks but I want to call specific distribution service. I have 3 distributions or agents, those are preview, publish and Publish to brand portal. In this case i want to publish only Publish to brand portal agent. Is it possible ?

Avatar

Level 6

Yes, you can call specific distribution service like this.

@Reference
private Replicator replicator; ReplicationOptions options = new ReplicationOptions(); options.setFilter(new AgentFilter() { @Override public boolean isIncluded (Agent agent) { return agent.getId().equals(DISTRIBITION_SERVICE_NAME); //PUBLISH or PREVIEW or any other distribution service you have } }); replicator.replicate(session,ReplicationActionType.ACTIVATE, assetPath, options);