> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://help.sigmacomputing.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://help.sigmacomputing.com/_mcp/server.

# Get the code representation of a data model

> Retrieve a Sigma data model as JSON or YAML code by calling the API Get code representation endpoint with the dataModelId.

You can retrieve a code representation of an existing data model by calling the [Get the code representation of a data model](/reference/get-data-model-spec) 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](/docs/manage-data-models-as-code).

## System and user requirements

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

* You must be the document owner or be granted **Can view** [access](/docs/folder-and-document-permissions) to the data model.
* You must have developer credentials for the Sigma API. For more information, see [Get started with the Sigma REST API](/reference/get-started-sigma-api).

## 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](/reference/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](/reference/list-data-models) endpoint to retrieve the `dataModelId`:

1. Go to your **Home** page.

2. In the navigation menu, select **Documents**.

3. Click the <img src="https://sigma-docs-screenshots.s3.us-west-2.amazonaws.com/Icons/caret.svg" alt="" /> **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](/reference/list-data-models) endpoint like the following:

   #### List data models request format

   ```shell
   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

```json
{
  "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
}
```

6. 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](/reference/get-data-model-spec) endpoint.

## Retrieve the representation

Using the `dataModelId`, make a GET request to the [Get the code representation of a data model](/reference/get-data-model-spec) endpoint using the following format:

#### Get a data model representation request format

```shell
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](/docs/example-representation-data-model-with-a-single-table).