Fetch linked document fields
Here we explore an example that fetches a specific content field from a linked document.
The fetchLinks parameter
The fetchLinks parameter allows you to retrieve a specific content field from a linked document and add it to the document response object.
Note that this will only retrieve content of the following field types:
- Content Relationship
- Key Text
- Rich Text (but only returns the first element)
It is not possible to retrieve the following content field types:
- Link to Media
- Rich Text (anything other than the first element)
- Any field in a Group or Slice
The value you enter for the fetchLinks option needs to take the following format:
The custom type API-ID of the linked document
The API-ID of the field you wish to retrieve from the linked document
A simple example
The following is an example that uses the fetchLinks parameter.
It shows how to query for the recipe with the uid "perfect-parfait". If the custom type "recipe" has a link to another custom type "author," then you can pull in certain fields from that linked document, in this case the "name" field.
Here are all the required parameters for this query:
is the type "recipe"
has the uid "perfect-parfait"
adds linked field
Fetch multiple fields
In order to fetch more than one field from the linked document, you just need to comma separate the desired fields. Here is an example that fetches the fields name and picture from the author custom type.
Was this article helpful?
Can't find what you're looking for? Get in touch with us on our Community Forum.