Access a Mendix Model Using Web API

Last modified: October 16, 2025

Introduction

This how-to describes how to use the Model Access API, which allows access to the Mendix model.

Using the Model Access API

The model is split in several components exposed via studioPro.app.model object. Currently supported components are:

  • buildingBlocks
  • domainModels
  • enumerations
  • pages
  • snippets

You can include these components using syntax as shown below, which includes pages and domain models.

In the following example, it is assumed you obtained the studioPro object by calling the factory function getStudioProApi.

const studioPro = getStudioProApi(componentContext);
const { pages, domainModels } = studioPro.app.model;

Reading the Units Info and Loading Units

A unit is a Mendix document (for example, a page or a domain model) containing elements. Each element resides within a container element and can itself contain other elements. Together, these elements form the logic of a Mendix model. For more information, see Mendix Metamodel.

Each component, for example pages (studioPro.app.model.pages) exposes the units it is responsible for. You can only access all the content of a unit once you have loaded the unit info for that unit.

The unit info, described by the UnitInfo interface, contains the the following fields:

Name Description Example value
$ID The unique id of the unit 077d1338-a548-49a9-baee-c291e93d19af
$Type The type of the unit Pages$Page
moduleName (Optional) The name of the module containing the unit MyFirstModule
name (Optional) The name of the unit ExamplePage

For example, you can retrieve all the units managed by the domainModels component using the following code:

const unitsInfo: Primitives.UnitInfo[] = await domainModels.getUnitsInfo()

A unit can be loaded by supplying a function, fn to component.loadAll(fn). The function fn should return true to load a specified unit.

Examples

The following code loads the domainModel for the module named MyFirstModule:

const [domainModel] = await domainModels.loadAll((info: Primitives.UnitInfo) => info.moduleName === 'MyFirstModule');

The next snippet loads the page Home_Web in the module MyFirstModule:

const [page] = await pages.loadAll((info: Primitives.UnitInfo) => info.moduleName === 'MyFirstModule' && info.name === 'Home_Web')

Reading the Unit Content

Elements within units can be accessed using the get<ElementName> helper methods.

For example, the following snippet will get the entity named MyEntity from the previously loaded DomainModels unit:

const entity: DomainModels.Entity = domainModel.getEntity("MyEntity");

Modifying the Unit Content

You can modify a Mendix model by leveraging the add<ElementName> helper methods.

The following snippet creates a new entity inside the previously loaded DomainModels unit:

const newEntity: DomainModels.Entity = await domainModel.addEntity({ name: "NewEntity", attributes: [{ name: "MyAttribute", type: "AutoNumber" }]});

newEntity.documentation = "New documentation";

await domainModels.save(domainModel);

Extensibility Feedback

If you would like to provide additional feedback, you can complete a small survey.

Any feedback is much appreciated.