Topic or Problem Statement
Fetch referenced entries using Javascript SDK.
Root Cause or Use Case
While fetching the entries through SDK only the uid of the referenced entry is fetched. User will have to include the references in the response if they wish to get the referenced entry.
Prerequisites to Resolve
-
The stack API key, delivery token, Environment name, Knowledge of Javascript SDK.
Steps to Resolve
When fetching an entry, the content of referred entries that are part of the parent entry is NOT included in the response body, you only get their UIDs. To include the content of the referred entries in your response, you need to use the includeReference() parameter and specify the UID of the reference field as value. Below is an example of the JS-SDK query with includeReference() parameter.
// Initialize the Contentstack Stack
const Contentstack = require('contentstack')
const Stack = Contentstack.Stack("stack_api_key", "delivery_token", "environment_name");
var Query = Stack.ContentType(‘contentType_uid’).Query();
Query
.includeReference('referenceField_uid')
.toJSON()
.find()
.then(function success(result) {
console.log(result);
})
Related Questions or Symptoms
-
Is it possible to include the reference field json content instead of just the uid while fetching the entry using JS-SDK?
Other Helpful Resources
-
The below documentation link will help you with the example code: https://www.contentstack.com/docs/platforms/javascript-browser/api-reference/Entry.html#includeReference