Generate a Logical Data Model Using the API

To generate the the logical data model (LDM) automatically using the API, follow these steps:

  1. Before you get started, learn how the PDM is transformed to the LDM and adjust your database as needed to make the process of generating the LDM smoother and more accurate.
  2. Generate the LDM from the stored PDM.
  3. Load the generated LDM definition to the workspace.

Generate the LDM from the Stored PDM

To generate the LDM from the stored PDM, submit a POST request to /api/v1/actions/dataSources/<data-source-id>/generateLogicalModel. <data-source-id> is the ID of the data source that corresponds to the database from which the PDM was generated.

As a result, a JSON file with a declarative definition of the LDM is generated.

Example: Generating the LDM based on the PDM stored under the demo-ds data source that represents the pre-installed PostgreSQL database with the sample data prepared in the GoodData.CN Community Edition image

The naming convention will be used for views, grains (primary keys), secondary labels, and references. The LDM definition will be saved to the ldm.json file.

Bash
PowerShell 7
curl $HOST_URL/api/v1/actions/dataSources/demo-ds/generateLogicalModel \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz" \
  -X POST \
  -d '{"separator": "__", "viewPrefix": "mtt", "grainPrefix": "gr", "secondaryLabelPrefix": "ls", "referencePrefix": "r"}' \
  | jq . > ldm.json
Invoke-RestMethod -Method Post -Uri "$HOST_URL/api/v1/actions/dataSources/demo-ds/generateLogicalModel" `
  -ContentType 'application/json' `
  -H @{ 
    'Accept' = 'application/json' 
    'Authorization' = 'Bearer YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz' 
  } `
  -Body '
{
  "separator": "__", 
  "viewPrefix": "mtt", 
  "grainPrefix": "gr", 
  "secondaryLabelPrefix": "ls", 
  "referencePrefix": "r"
}' | ConvertTo-Json > ldm.json

Load the Generated LDM Definition to the Workspace

To load the LDM definition to the workspace, submit a PUT request to /api/v1/actions/workspaces/<workspace-id>/logicalModel. <workspace-id> is the ID of the workspace where you want to load the LDM to.

Example: Loading the LDM definition to the demo workspace

Bash
PowerShell 7
curl $HOST_URL/api/v1/layout/workspaces/demo/logicalModel \
  -H "Authorization: Bearer YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz" \
  -H "Content-Type: application/json" \
  -X PUT -d @ldm.json
Invoke-RestMethod -Method Put -Uri "$HOST_URL/api/v1/layout/workspaces/demo/logicalModel" `
  -ContentType 'application/json' `
  -H @{ 'Authorization' = 'Bearer YWRtaW46Ym9vdHN0cmFwOmFkbWluMTIz' } `
  -InFile ldm.json

Once you have the LDM generated, you can start building dashboards and visualizations.