---
title: "Swap template data sources"
method: POST
path: "/v2/templates/{templateId}/swapSources"
tags: ["Templates"]
---

# Swap template data sources

`POST /v2/templates/{templateId}/swapSources`

## Request

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

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

  ### Usage notes
  - Retrieve the **templateId** by calling the [/v2/templates](https://help.sigmacomputing.com/reference/list-templates) endpoint.
  - Retrieve the **connectionId** to use as the **toId** 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:

    - Retrieve the **fromId** for a specific data element by calling the [/v2/workbooks/{workbookId}/lineage/elements/{elementId}](https://help.sigmacomputing.com/reference/list-lineage) endpoint and using the `source` key from the response, which looks like `inode-2PBoXx3UabchxF1F3l07kE`. The ID is everything after `inode-`.
    - 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.

## Path parameters

- `templateId` string, required

## Request body

- object
  - `sourceMapping` V2TemplatesTemplateIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItems[]
    - `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` V2TemplatesTemplateIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsMetricMappingItems[]
      - `fromMetric` string, required: Metric in the data source.
      - `toMetric` string, required: Metric in the data source.
    - `columnMapping` V2TemplatesTemplateIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItems[]
      - `fromColumn` union, required
        - string
        - string[]
      - `toColumn` union, required
        - string
        - string[]
  - `connectionMapping` V2TemplatesTemplateIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaConnectionMappingItems[]
    - `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` V2TemplatesTemplateIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaConnectionMappingItemsPathsItems[]
      - `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.

- TemplatesSourceSwapTemplateResponse200
  - `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)
