Skip to main content
Level 4
January 22, 2024

How can I call an author api by java code

I just want to call aem ootp api like '/libs/wcm/core/content/reference.json' by java code in author. Are there any convenient ways to do this? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

16 replies

Level 7
January 22, 2024

Hi @johann_lu 

 

You can call that API, similar to how would you call 3rd party API. 

Translate
Johann_LuAuthor
Level 4
January 22, 2024

But when I call author apis, it needs account and password, I just want some convenient ways to call these api.

Translate
Level 7
January 22, 2024

Hi @johann_lu 

Usually in publish environment, for the anonymous user: user has restricted permissions only. ie /content /bin.  In your case, you need to give read permission to the path "/libs/wcm/core/content/" for the anonymous user. Is this the right way?? Not sure.

Or else, you need to create some proxy servlet, that will internally call /libs/wcm/core/content/.  

Translate
Mahedi_Sabuj
Community Advisor
Community Advisor
January 22, 2024

You can use AssetReferenceSearch get the resources referenced by the page. It's constructor takes the node (content node of the page ) to search under, path where the assets are stored (can be /content/dam ) and Resource Resolver.

String Pagepath = "/content/we-retail/en"; //This would be your page path Resource r = resourceResolver.getResource(Pagepath + "/" + JcrConstants.JCR_CONTENT); Node n = r.adaptTo(Node.class); AssetReferenceSearch ref = new AssetReferenceSearch (n, DamConstants.MOUNTPOINT_ASSETS, resourceResolver); Map<String,Asset> allref = new HashMap<String,Asset>(); allref.putAll(ref.search()); for (Map.Entry<String, Asset> entry : allref.entrySet()) { String val = entry.getKey(); out.println(val+"<br>"); // Path of all Asset ref in page Asset asset = entry.getValue(); }

Reference: https://stackoverflow.com/questions/30892111/how-to-get-detail-of-all-digital-assets-used-in-single-webpage-in-aem 

 

 

Translate
Mahedi Sabuj
Johann_LuAuthor
Level 4
January 22, 2024

What about template and policy?

Translate
Johann_LuAuthor
Level 4
January 23, 2024

I have checked it before, it didn't work, the result is null

Translate
arunpatidar
Community Advisor
Community Advisor
January 23, 2024
kautuk_sahni
Adobe Employee
Adobe Employee
January 23, 2024

@johann_lu Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Translate
Kautuk Sahni
Johann_LuAuthor
Level 4
January 24, 2024

What they said I have tried before, but those didn't work.

Translate
Level 2
May 14, 2024

I have the same requirement as yours, I stumbled upon this article it might help

https://kiransg.com/2023/05/16/sling-servlet-helpers/

Translate