Hi,
I would like to know if there is a way to get the list of references of an asset through APIs.
Thank you.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi,
You can use the ReferenceSearch API https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/wcm/common... or depending on what you need, you can use the AssetSearchReference https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/dam/common... as well.
Hope this helps
Hi @EstebanBustamante ,
Tried both api not getting the result. Which asset path has to passed as params? can you please share the example code snippet.
Views
Replies
Total Likes
Sure, check this out: https://github.com/Adobe-Marketing-Cloud/aem-samples/blob/master/tutorial-referenced-assets/bundle/s...
And this one: https://experience-aem.blogspot.com/2015/07/aem-61-get-references-of-page-or-asset.html
Hi @EstebanBustamante ,
This asset is actually spinset. Using api it's returning spinset members as a results instead of reference asset path. Is this api applicable for spinset/imageset/mixedmediaset assets?
What @EstebanBustamante said, and here's some very simple example code, this is sandbox code for learning only:
package com.sourcedcode.core.services.impl;
import com.day.cq.commons.ReferenceSearch;
import com.day.cq.commons.ReferenceSearch.Info;
import com.example.core.services.AssetReferenceFinder;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.osgi.service.component.annotations.Component;
import java.util.List;
import java.util.Map;
@Component(service = AssetReferenceFinder.class, immediate = true)
public class AssetReferenceFinderImpl implements AssetReferenceFinder {
@Override
public List<Info> getReferences(ResourceResolver resourceResolver, String assetPath) {
Resource assetResource = resourceResolver.getResource(assetPath);
if (assetResource == null) {
throw new IllegalArgumentException("Asset not found at path: " + assetPath);
}
ReferenceSearch referenceSearch = new ReferenceSearch();
Map<String, String> params = ReferenceSearch.getDefaultParams();
return referenceSearch.search(assetResource, params);
}
}
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
....
List<Info> references = assetReferenceFinder.getReferences(resourceResolver, assetPath);
// Use Gson to build JSON response
Gson gson = new Gson();
JsonArray referencesJsonArray = new JsonArray();
for (Info info : references) {
JsonObject referenceJson = new JsonObject();
referenceJson.addProperty("nodePath", info.getNodePath());
referenceJson.addProperty("propertyName", info.getPropertyName());
referenceJson.addProperty("type", info.getType());
referencesJsonArray.add(referenceJson);
}
// Write JSON array to the response
response.setContentType("application/json");
response.getWriter().write(gson.toJson(referencesJsonArray));
@Keerthana_H_N Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies