Hi @pcardno,
In general HTTP Asset API is not supporting either listing of relationships, or managing (adding, removing) relationship between the assets.
I would suggest to explore below options.
- Write your own servlet that will handle what you need using Asset Java api (mainly Asset, AssetManager, AssetRelation). Here is a very simple code snippet that is setting relationship between 2 assets.
import com.adobe.granite.asset.api.Asset;
import com.adobe.granite.asset.api.AssetManager;
AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class);
if (assetManager != null) {
Asset asset = assetManager.getAsset("/content/dam/we-retail-screens/usa.png");
/**
* First param represents relation type/name - possible values seources, derived, others
* Second param represents path to asset that will be related to given asset
*/
asset.addRelation("others", "/content/dam/we-retail-screens/we-retail-instore-logo.png");
resourceResolver.commit();
}
- You can try to utilize OOTB ManageReferencesServlet, in general this servlet is use when you managing relation via GUI. It base on manageReferences selector, and supports 2 HTTP methods: GET and POST. GET will allow you to list information about relation for given asset(s), POST is used do manipulate relation (add, remove).
// GET
/content/dam/we-retail-screens/usa.manageReferences.png?item=/content/dam/we-retail-screens/usa.png
You should simply use manageReferences selector and item param, one request can contain multiple item parameters, e.g
/content/dam/we-retail-screens/usa.manageReferences.png?item=/content/dam/we-retail-screens/usa.png&item=/content/dam/we-retail-screens/italy.png
For POST I would suggest to experiment with network tab from dev tools in the browser, and maybe record POST request to get better idea/understanding what data/format is sent. You can expect that information about relation will be passed via JSON param that could look like this:
"{\"/content/dam/we-retail-screens/usa.png\":{\"name\":\"usa.png\",\"sources\":{},\"derived\":{\"/content/dam/we-retail-screens/italy.png\":{\"name\":\"\"}},\"others\":{\"/content/dam/we-retail-screens/we-retail-instore-logo.png\":{\"name\":\"we-retail-instore-logo.png\"}},\"relationName\":\"derived\"},\"/content/dam/we-retail-screens/italy.png\":{\"name\":\"italy.png\",\"sources\":{\"/content/dam/we-retail-screens/usa.png\":{\"name\":\"\"}},\"derived\":{},\"others\":{},\"relationName\":\"sources\"}}"
Please be aware that if you will go with approach number 2 you will also need to make sure to assure some authentication - because ManageReferencesServlet is not available publically - you have to be logged in to use it.
Saying that, I would rather recommend option 1, mainly because it will give you full control of HTTP contract of your endpoint etc (what methods, params you will use etc) and backend implementation - especially that Java Asset api gives you all you need. The other thing is that if you will use option 2, there is a chance something will change in the future in terms of ManageReferencesServlet contract and your solution will stop working.