Get the code representation of a data model

You can retrieve a code representation of an existing data model by calling the Get the code representation of a data model endpoint with the dataModelId for the data model.

This document provides step-by-step instructions for using this endpoint to retrieve the representation of an existing data model. For more information on working with data models programmatically, see Manage data models as code.

System and user requirements

The ability to retrieve the representation of a data model requires the following:

Generate API client credentials and an API access token

To start, you must generate credentials for the Sigma API. These credentials are used to retrieve an access token, which is required to make requests to the API.

For step-by-step instructions on generating developer credentials in Sigma and using them to authenticate to the Sigma API, see the instructions in Generate client credentials.

Identify the data model and retrieve the data model ID

To retrieve the code representation of an existing data model, you must know the unique dataModelId for that data model. When you have identified the data model you want to retrieve the representation for, you can call the List data models endpoint to retrieve the dataModelId:

  1. Go to your Home page.

  2. In the navigation menu, select Documents.

  3. Click the Document type filter and select Data models.

    The list of your data models appears.

  4. Identify the data model you want to retrieve the representation for by name, owner, or other details.

  5. Make a GET request to the List data models endpoint like the following:

    List data models request format
    curl --request GET \
        --url <base_url>/v2/dataModels \
        --header 'Authorization: Bearer <access_token>' \
        --header 'accept:application/json' \
        --header 'content-type: application/x-www-form-urlencoded'

The response includes a list of data models in your organization, in the following format:

List data models response format
{
  "entries":
    [
      {
        "dataModelId": "<dataModelId>",
        "dataModelUrlId": "<dataModelUrlId>",
        "createdBy": "<userId>",
        "updatedBy": "<userId>",
        "createdAt": "<timestamp>",
        "updatedAt": "<timestamp>",
        "name": "<dataModelName>",
        "url": "<dataModelUrl>",
        "path": "<folderPath>",
        "latestVersion": "<versionNumber>",
        "ownerId": "<userId>"
      },
      {
        "dataModelId": "<dataModelId>",
        "dataModelUrlId": "<dataModelUrlId>",
        "createdBy": "<userId>",
        "updatedBy": "<userId>",
        "createdAt": "<timestamp>",
        "updatedAt": "<timestamp>",
        "name": "<dataModelName>",
        "url": "<dataModelUrl>",
        "path": "<folderPath>",
        "latestVersion": "<versionNumber>",
        "ownerId": "<userId>"
      }
    ],
  "hasMore": <boolean>,
  "total": <number>,
  "nextPage": null
}
  1. Identify the data model you want to retrieve the representation for, and copy the dataModelId to pass to the Get the code representation of a data model endpoint.

Retrieve the representation

Using the dataModelId, make a GET request to the Get the code representation of a data model endpoint using the following format:

Get a data model representation request format
curl --request GET \
    --url <base_url>/v2/dataModels/<dataModelId>/spec \
    --header 'Authorization: Bearer <access_token>' \
    --header 'content-type: application/x-www-form-urlencoded'

The response body contains a JSON representation of the data model for the specified dataModelId.

To see an example of a data model representation along with the instructions used to create it in the Sigma UI, see Data model with a single table.