Skip to main contentGet the benchmark report: Where does your team stand on AI adoption?
CONTACT SALESSTART BUILDING

To fetch or load references or Symbols, you must use enrich in your calls to fetch multiple entries from Builder.

Pass in the options object with enrich: true when using getAll() in a Gen 1 SDK and fetchEntries() in a Gen 2 SDK. This provides a consistent experience between the Visual Editor and the live site.

Tip: The enrich attribute returns the fetched reference and three additional layers of depth for nested references. If you access a reference or Symbol with more than 3 layers of nested references, later layers will not be enriched.

Tip: Builder enriches by default for Gen 1's builder.get() and Gen 2's fetchOneEntry().

To fetch or load references or Symbols, be sure to manually pass in enrich: true when using getAll().

import { builder } from '@builder.io/react';

const pages = await builder.getAll('page', {
  // to fetch references and Symbols
  options: { enrich: true }
});

When enriching data from the Content API, you may wish to exclude some fields or include only specific fields. When enrich is set to true, use the enrichOptions key to define precisely what information to receive.

enrichOptions accepts an object with two possible values:

  1. model: This key expects an object where each key is the name of a Model and each value is an object. Each object should include either the fields key, representing which fields to include, the omit key, representing which fields to exclude, or both keys.
  2. enrichLevel: This key accepts a value greater than 0 and determines the depth level for enriching. For example, an enrichLevel of 1 would return one additional nested model within the original response. The max level is 4.
import { builder } from "@builder.io/react";

const entry = await builder.get('post', {
  ...
  options: { 
    enrich: true,
    enrichOptions: {
      model: {
        author: {
          fields: "id,name,data",
          omit: "data.blocks",
        },
        category: {
          fields: "id,name",
        },
      },
      enrichLevel: 2,
    },
  },
  ...
})

The example above demonstrates a request to a post model with two nested models: author and category. For author, the name, id, and data values are included in the response, except the data.blocks value is exclude.

For the category model, only id and name are included in the response. Finally, with enrichLevel set to 2, two additional levels of depth will be included within the response, nested within the post model.

For more detail on the Gen 2 (or Mitosis) SDKs, see the Builder GitHub repo.

Was this article helpful?