---
title: "Swap data model sources"
method: POST
path: "/v2/dataModels/{dataModelId}/swapSources"
tags: ["Data models"]
---

# Swap data model sources

`POST /v2/dataModels/{dataModelId}/swapSources`

## Request

- Base URL: `https://api.sigmacomputing.com`
- URL: `https://api.sigmacomputing.com/v2/dataModels/{dataModelId}/swapSources`
- Auth: HTTP bearer

Swap the data sources used by a data model. You can swap from one connection to another, and/or from one dataset or table to another.

  ### Usage notes
  - Retrieve the **dataModelId** by calling the [/v2/dataModels](https://help.sigmacomputing.com/reference/list-data-models) endpoint.
  - Retrieve the **connectionId** by calling the [/v2/connections](https://help.sigmacomputing.com/reference/list-connections) endpoint.
  - To map the sources of a specific element, you can use the table or dataset ID:

    - List sources of data model by calling the [/v2/dataModels/{dataModelId}/sources](https://help.sigmacomputing.com/reference/list-data-model-sources) endpoint.
    - Retrieve table and dataset IDs by calling the [/v2/files](https://help.sigmacomputing.com/reference/list-files) endpoint. Use the `typeFilters` option to filter for table and dataset files. Use `id` field in the response as the `fromId` or `toId`, as relevant.

  - To swap warehouse tables in a connection, set the `swapTables` option to `true`.

    - Use the `paths` option to specify the connection paths to swap. The connection path is a list of strings that represents the path to the table in the cloud data warehouse. For example, `["database", "schema", "table"]`.
    - If the table schema is the same in both connections, leave the `paths` option empty to swap all warehouse tables in the connection. You can also pass a partial path to swap between databases, catalogs, or schemas.
    - If `sourceMapping` is provided, those mappings take precedence over the connection swaps.
    - If `swapTables` is not set to `true`, warehouse tables stay on the original connection. Custom SQL elements and input tables still follow the connection mapping.

  ### Usage scenarios
  - **Data model development**: Use a test data source while developing a data model, then swap the source to a production database when ready to share the data model for production use.

## Path parameters

- `dataModelId` string, required

## Request body

- object
  - `sourceMapping` V2DataModelsDataModelIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItems[]
    - `fromId` string, required: ID of the dataset (deprecated) or table to swap from.
    - `toId` string, required: ID of the dataset (deprecated) or table to swap to.
    - `metricMapping` V2DataModelsDataModelIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsMetricMappingItems[]
      - `fromMetric` string, required: Metric in the data source.
      - `toMetric` string, required: Metric in the data source.
    - `columnMapping` V2DataModelsDataModelIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItems[]
      - `fromColumn` union, required
        - string
        - string[]
      - `toColumn` union, required
        - string
        - string[]
  - `connectionMapping` V2DataModelsDataModelIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaConnectionMappingItems[]
    - `fromId` string, required: ID of the connection to swap from.
    - `toId` string, required: ID of the connection to swap to.
    - `swapTables` boolean: Whether to swap warehouse tables in the connection.
    - `paths` V2DataModelsDataModelIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaConnectionMappingItemsPathsItems[]
      - `fromPath` string[], required: Connection path of the form ['DATABASE', 'SCHEMA', 'TABLE']
      - `toPath` string[], required: Connection path of the form ['DATABASE', 'SCHEMA', 'TABLE']
  - `copyInputTableData` boolean

## Response `200`

The response body.

- DataModelsSwapDataModelSourcesResponse200
  - `unswappedSources` string[], required: IDs of sources in the workbook that were not swapped.
  - `unswappedConnections` string[], required: IDs of custom SQL connections in the workbook that were not swapped.

---

[API](https://skmtc.dev/sigmacomputing/apis/sigma-rest-api.md) - [All operations](https://skmtc.dev/sigmacomputing/apis/sigma-rest-api/llms.txt) - [OpenAPI document](https://skmtc.dev/sigmacomputing/apis/sigma-rest-api/revisions/fb6036208c49?raw)
