Magnolia 5.7 reached extended end of life on May 31, 2022. Support for this branch is limited, see End-of-life policy. Please note that to cover the extra maintenance effort, this EEoL period is a paid extension in the life of the branch. Customers who opt for the extended maintenance will need a new license key to run future versions of Magnolia 5.7. If you have any questions or to subscribe to the extended maintenance, please get in touch with your local contact at Magnolia.
This page explains how to use the delivery endpoint so that it resolves references to nodes from different workspaces.
The information on this page only applies to delivery endpoint API v2. If you want to resolve references with version 1, see Delivery endpoint API v1 - reference resolving configuration.
What is reference resolving?
The endpoints of the delivery API are configured to return content as JSON from one JCR workspace (configured with the workspace
property).
Here is a JSON response of a tour from the workspace tours
.
{ "@name": "Kyoto", "@path": "/magnolia-travels/Kyoto", "@id": "b475f27e-2929-427b-9517-815118a3b36e", "@nodeType": "mgnl:content", "body": "<p>Experience the still beauty that permeates and surrounds Kyoto. Kyoto is famous for many things, including countless <a href=\"http://www.japan-guide.com/e/e2058.html\" style=\"text-decoration:none;\" target=\"_blank\"><u>temples</u></a>, <a href=\"http://www.japan-guide.com/e/e2059.html\" style=\"text-decoration:none;\" target=\"_blank\"><u>shrines</u></a> and other fascinating historical buildings.</p>\n<p>Join us on a visit to the City of Ten Thousand Shrines. We'll visit Tō-ji, Ginkaku-ji, Kōzan-ji and their remarkable gardens before venturing into the mountains that surround the city. You’ll enjoy a day spent in green Miyama and a day hiking in Shizuhara. You’ll never think about Japan in the same way again.</p> ", "name": "Kyoto", "description": "The natural side of Japan", "destination": [ "7ec72c48-c33f-418e-b2ff-44cfb4bbb1f2" ], "location": "Kyoto, Japan", "tourTypes": [ "d2245867-ecaa-4b4e-8743-e0c939be68b7", "415025c6-e4b5-4506-9384-34f428a52104" ], "author": "Magnolia Travels", "duration": "7", "image": "jcr:44689d29-5966-4d41-8fd4-2dc7da783528", "@nodes": [] }
- Lines 13-15: The
tourTypes
property contains two references to tour type nodes that reside in thecategory
workspace. Line 19: The
image
property contains the asset identifier, which is the reference to an asset. In this case the asset is stored in the Magnolia DAM in thedam
workspace. In other cases, the asset could be in another asset provider.
We could send additional requests to deliver content for the category
and dam
workspaces. However, it is more efficient to get the data of the referenced nodes directly with the first request by resolving the references.
In the following sections, we show you how to configure the delivery endpoint in order to resolve the references.
Details concerning the example:
The JSON is requested with this URL: http://localhost:8080/magnoliaAuthor/.rest/tours/magnolia-travels/Kyoto
The basic configuration for the delivery endpoint to read tours in the example so far is:
class: info.magnolia.rest.delivery.jcr.v2.JcrDeliveryEndpointDefinition workspace: tours includeSystemProperties: false #references
The references
and the referenceResolver
properties
The references
property is used in both (for delivery endpoint API v1) and
(for the delivery endpoint API v2). On this page we focus on v2.
Configuration example:
references: - name: tourTypeReference propertyName: tourTypes referenceResolver: class: info.magnolia.rest.reference.jcr.JcrReferenceResolverDefinition targetWorkspace: category
Properties
references | The references node contains a list of reference definitions. The properties of a single reference are defined in |
| optional An arbitrary name. If you do not set the property, the first property must start with a |
| required The value of this property contains the name of the JCR node property that stores one or multiple references to nodes of other workspaces. |
| optional The value must be a valid node type. If set, references are resolved only on nodes of the given type. |
| required The reference resolver defines how references are resolved, the properties are defined in |
| required The value must refer to a class or interface extending Reference resolver definition classes provided by Magnolia:
Note that these classes may have further properties that must be configured. |
Resolving jcr node references
Magnolia provides a JCR node reference resolver that is suitable in most cases, with the exception of assets. Use the definition class for configuration.
Example configuration
This example is based on the basic configuration shown above.
class: info.magnolia.rest.delivery.jcr.v2.JcrDeliveryEndpointDefinition workspace: tours includeSystemProperties: false references: - name: tourTypeReference propertyName: tourTypes referenceResolver: class: info.magnolia.rest.reference.jcr.JcrReferenceResolverDefinition targetWorkspace: category expand: true generateLink: true
The lines 5-11 define how the references stored in the field tourTypes
are resolved.
Properties
class | required Must be |
targetWorkspace | required The name of the workspace containing the nodes that are referenced. |
expand | optional, default is If set to If |
generateLink | optional, default is If The format of the generated links depends on the configuration of the link generator (configured in |
Resolving asset references
Magnolia REST modules come with an asset resolver, which creates a (relative) link to the image as well as Dublin Core metadata (if it exists for the asset). Use the definition class for configuration.
The Magnolia asset resolver operates on the DAM API - this ensures it can resolve assets from any asset provider such as Cumulus DAM connector or Amazon S3 Connector.
If the referenced assets reside in the Magnolia DAM, the asset resolver can also generate links to asset renditions (also known as image variations). Renditions must be defined in the theme that is linked to the site definition. See image variations to learn how to define asset renditions in a theme.
For image variations to be resolved correctly, make sure that the fallback site has theme variations configured or extends a site definition with desired variations.
Example configuration
This example is based on the basic configuration shown above.
class: info.magnolia.rest.delivery.jcr.v2.JcrDeliveryEndpointDefinition workspace: tours includeSystemProperties: false references: - name: tourImageReference propertyName: image referenceResolver: class: info.magnolia.rest.reference.dam.AssetReferenceResolverDefinition assetRenditions: - 320x240 - 1600x1200 - nonexistent
The lines 5-11 define how the references stored in the dam
workspace are resolved.
Properties
class | required Must be |
expand | optional , default is If set to If |
includeDownloadLink | optional, default is If set to |
includeAssetMetadata | optional, default is If set to |
assetRenditions | optional A list of rendition names as defined in the theme linked to the current site. |
| required The rendition name. If you add an undefined – and therefore non-existent rendition – the asset resolver creates a link to the default variation which is the same as the asset in its original size. |
6 Comments
Christoph Meier
Christoph Meier - Resolving asset references works also for assets residing on Amazon S3 Connector module.
Here is a gist from Alberto, which works fine.
Add a note to this page and on DOCS60.
Marvin Kerkhoff
Hi, is there a way to get nested references resolved? For example a DAM asset inside a referenced object?
Christoph Meier
tbh - I have never tried this.
But good idea ... I should try this out ...
Loukas Andreadelis
Christoph Meier Have you given nested references resolution a try or it's only possible with custom Java endpoints?
Christoph Meier
Hi Loukas
I haven't tried it out. Sorry.
Loukas Andreadelis
Hi Christoph
All my tests to existing api haven't managed to get nested reference resolution. It's only for root level.
Looks like it's not feasible, only solution is custom.