> 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.

# Swap report data sources

POST https://api.sigmacomputing.com/v2/reports/{reportId}/swapSources
Content-Type: application/json

Swap each data source used by a report. You can swap from one table, dataset (deprecated), or data model element to another for each data source.

### Usage notes
- Retrieve the **reportId** by calling the [/v2/reports](https://help.sigmacomputing.com/reference/list-reports) endpoint.
- Retrieve report sources by calling the [/v2/reports/{reportId}/sources](https://help.sigmacomputing.com/reference/list-report-sources) endpoint.
- Retrieve the **dataModelId** by calling the [/v2/dataModels](https://help.sigmacomputing.com/reference/list-data-models) endpoint.
- Retrieve the **datasetId** by calling the [/v2/datasets](https://help.sigmacomputing.com/reference/list-datasets) endpoint.
- Retrieve the **tableId** by calling the [/v2/connection](https://help.sigmacomputing.com/reference/lookup-connection) endpoint.

- Use the `sourceMapping` options in the request body to swap specific sources. For each source in the source mapping, provide the current source in use in the **from** object, and provide the source that you want to use instead in the **to** object.
- If your source is a data model with one or more tagged versions, you can also provide a `versionTagId` to swap to or from a tagged version of the data model. The data model version must already be tagged.
- If your source is a data model or a dataset, you can use the `metricMapping` option to map metrics that rely on column names from the old source to the new one so that they continue to work.
- If the source that you swap from uses column names, links, or relationships different from the source that you are swapping to, use the `columnMapping` option to map each column in the original source to a corresponding column in the new source.

### Usage scenarios
- **Report development**: Use a test data source during development, then swap to a production source when ready to share the report.
- **Dataset migration**: Update references to deprecated dataset sources with data model sources by mapping dataset IDs to their new data model equivalents.


Reference: https://help.sigmacomputing.com/reference/source-swap-report

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: sigma-rest-api
  version: 1.0.0
paths:
  /v2/reports/{reportId}/swapSources:
    post:
      operationId: sourceSwapReport
      summary: Swap report data sources
      description: >
        Swap each data source used by a report. You can swap from one table,
        dataset (deprecated), or data model element to another for each data
        source.


        ### Usage notes

        - Retrieve the **reportId** by calling the
        [/v2/reports](https://help.sigmacomputing.com/reference/list-reports)
        endpoint.

        - Retrieve report sources by calling the
        [/v2/reports/{reportId}/sources](https://help.sigmacomputing.com/reference/list-report-sources)
        endpoint.

        - Retrieve the **dataModelId** by calling the
        [/v2/dataModels](https://help.sigmacomputing.com/reference/list-data-models)
        endpoint.

        - Retrieve the **datasetId** by calling the
        [/v2/datasets](https://help.sigmacomputing.com/reference/list-datasets)
        endpoint.

        - Retrieve the **tableId** by calling the
        [/v2/connection](https://help.sigmacomputing.com/reference/lookup-connection)
        endpoint.


        - Use the `sourceMapping` options in the request body to swap specific
        sources. For each source in the source mapping, provide the current
        source in use in the **from** object, and provide the source that you
        want to use instead in the **to** object.

        - If your source is a data model with one or more tagged versions, you
        can also provide a `versionTagId` to swap to or from a tagged version of
        the data model. The data model version must already be tagged.

        - If your source is a data model or a dataset, you can use the
        `metricMapping` option to map metrics that rely on column names from the
        old source to the new one so that they continue to work.

        - If the source that you swap from uses column names, links, or
        relationships different from the source that you are swapping to, use
        the `columnMapping` option to map each column in the original source to
        a corresponding column in the new source.


        ### Usage scenarios

        - **Report development**: Use a test data source during development,
        then swap to a production source when ready to share the report.

        - **Dataset migration**: Update references to deprecated dataset sources
        with data model sources by mapping dataset IDs to their new data model
        equivalents.
      tags:
        - Reports
      parameters:
        - name: reportId
          in: path
          required: true
          schema:
            type: string
        - name: Authorization
          in: header
          description: OAuth authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: The response body.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/reports_sourceSwapReport_Response_200'
      requestBody:
        description: The request body.
        content:
          application/json:
            schema:
              type: object
              properties:
                sourceMapping:
                  type: array
                  items:
                    $ref: >-
                      #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItems
              required:
                - sourceMapping
servers:
  - url: https://api.sigmacomputing.com
    description: Server for GCP (US) hosted organizations
  - url: https://api.sa.gcp.sigmacomputing.com
    description: Server for GCP (KSA) hosted organizations
  - url: https://aws-api.sigmacomputing.com
    description: Server for AWS US (West) hosted organizations
  - url: https://api.us-a.aws.sigmacomputing.com
    description: Server for AWS US (East) hosted organizations
  - url: https://api.ca.aws.sigmacomputing.com
    description: Server for AWS Canada hosted organizations
  - url: https://api.eu.aws.sigmacomputing.com
    description: Server for AWS Europe hosted organizations
  - url: https://api.au.aws.sigmacomputing.com
    description: Server for AWS Australia and APAC hosted organizations
  - url: https://api.uk.aws.sigmacomputing.com
    description: Server for AWS UK hosted organizations
  - url: https://api.us.azure.sigmacomputing.com
    description: Server for Azure US hosted organizations
  - url: https://api.eu.azure.sigmacomputing.com
    description: Server for Azure Europe hosted organizations
  - url: https://api.ca.azure.sigmacomputing.com
    description: Server for Azure Canada hosted organizations
  - url: https://api.uk.azure.sigmacomputing.com
    description: Server for Azure United Kingdom hosted organizations
  - url: https://api.au.azure.sigmacomputing.com
    description: Server for Azure Australia hosted organizations
components:
  schemas:
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf0Type:
      type: string
      enum:
        - table
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf0Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom0:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf0Type
        tableId:
          type: string
      required:
        - type
        - tableId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom0
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf1Type:
      type: string
      enum:
        - dataset
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf1Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom1:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf1Type
        datasetId:
          type: string
      required:
        - type
        - datasetId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom1
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf2Type:
      type: string
      enum:
        - data-model
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf2Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom2:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf2Type
        dataModelId:
          type: string
        elementId:
          type: string
          description: ID of the element in the data model
        versionTagId:
          type: string
      required:
        - type
        - dataModelId
        - elementId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom2
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf3Type:
      type: string
      enum:
        - custom-sql
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf3Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom3:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFromOneOf3Type
        customSqlId:
          type: string
          description: ID of the element associated with the custom SQL element.
      required:
        - type
        - customSqlId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom3
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom:
      oneOf:
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom0
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom1
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom2
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom3
      description: Source to swap from.
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf0Type:
      type: string
      enum:
        - table
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf0Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo0:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf0Type
        tableId:
          type: string
      required:
        - type
        - tableId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo0
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf1Type:
      type: string
      enum:
        - dataset
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf1Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo1:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf1Type
        datasetId:
          type: string
      required:
        - type
        - datasetId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo1
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf2Type:
      type: string
      enum:
        - data-model
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf2Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo2:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf2Type
        dataModelId:
          type: string
        elementId:
          type: string
          description: ID of the element in the data model
        versionTagId:
          type: string
      required:
        - type
        - dataModelId
        - elementId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo2
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf3Type:
      type: string
      enum:
        - custom-sql
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf3Type
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo3:
      type: object
      properties:
        type:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsToOneOf3Type
        connectionId:
          type: string
          description: >-
            ID of the connection that the new custom SQL element will run
            against.
        definition:
          type: string
          description: SQL query that defines the new custom SQL element.
      required:
        - type
        - connectionId
        - definition
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo3
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo:
      oneOf:
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo0
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo1
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo2
        - $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo3
      description: Source to swap to.
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsMetricMappingItems:
      type: object
      properties:
        fromMetricId:
          type: string
          description: Identifier of the metric in the data source
        toMetricId:
          type: string
          description: Identifier of the metric in the data source
      required:
        - fromMetricId
        - toMetricId
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsMetricMappingItems
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItemsFromColumn:
      oneOf:
        - type: array
          items:
            type: string
        - type: array
          items:
            type: string
        - type: array
          items:
            type: string
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItemsFromColumn
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItemsToColumn:
      oneOf:
        - type: array
          items:
            type: string
        - type: array
          items:
            type: string
        - type: array
          items:
            type: string
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItemsToColumn
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItems:
      type: object
      properties:
        fromColumn:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItemsFromColumn
        toColumn:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItemsToColumn
      required:
        - fromColumn
        - toColumn
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItems
    V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItems:
      type: object
      properties:
        from:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsFrom
          description: Source to swap from.
        to:
          $ref: >-
            #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsTo
          description: Source to swap to.
        metricMapping:
          type: array
          items:
            $ref: >-
              #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsMetricMappingItems
        columnMapping:
          type: array
          items:
            $ref: >-
              #/components/schemas/V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItemsColumnMappingItems
      required:
        - from
        - to
      title: >-
        V2ReportsReportIdSwapSourcesPostRequestBodyContentApplicationJsonSchemaSourceMappingItems
    reports_sourceSwapReport_Response_200:
      type: object
      properties: {}
      title: reports_sourceSwapReport_Response_200
  securitySchemes:
    OAuth:
      type: http
      scheme: bearer
      description: OAuth 2.0 authentication

```

## Examples



**Request**

```json
{
  "sourceMapping": [
    {
      "from": {
        "tableId": "string",
        "type": "table"
      },
      "to": {
        "tableId": "string",
        "type": "table"
      }
    }
  ]
}
```

**Response**

```json
{}
```

**SDK Code**

```python
import requests

url = "https://api.sigmacomputing.com/v2/reports/reportId/swapSources"

payload = { "sourceMapping": [
        {
            "from": {
                "tableId": "string",
                "type": "table"
            },
            "to": {
                "tableId": "string",
                "type": "table"
            }
        }
    ] }
headers = {
    "Authorization": "<token>.",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.sigmacomputing.com/v2/reports/reportId/swapSources';
const options = {
  method: 'POST',
  headers: {Authorization: '<token>.', 'Content-Type': 'application/json'},
  body: '{"sourceMapping":[{"from":{"tableId":"string","type":"table"},"to":{"tableId":"string","type":"table"}}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.sigmacomputing.com/v2/reports/reportId/swapSources"

	payload := strings.NewReader("{\n  \"sourceMapping\": [\n    {\n      \"from\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      },\n      \"to\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      }\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "<token>.")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.sigmacomputing.com/v2/reports/reportId/swapSources")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<token>.'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"sourceMapping\": [\n    {\n      \"from\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      },\n      \"to\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      }\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.sigmacomputing.com/v2/reports/reportId/swapSources")
  .header("Authorization", "<token>.")
  .header("Content-Type", "application/json")
  .body("{\n  \"sourceMapping\": [\n    {\n      \"from\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      },\n      \"to\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      }\n    }\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.sigmacomputing.com/v2/reports/reportId/swapSources', [
  'body' => '{
  "sourceMapping": [
    {
      "from": {
        "tableId": "string",
        "type": "table"
      },
      "to": {
        "tableId": "string",
        "type": "table"
      }
    }
  ]
}',
  'headers' => [
    'Authorization' => '<token>.',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.sigmacomputing.com/v2/reports/reportId/swapSources");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<token>.");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"sourceMapping\": [\n    {\n      \"from\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      },\n      \"to\": {\n        \"tableId\": \"string\",\n        \"type\": \"table\"\n      }\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<token>.",
  "Content-Type": "application/json"
]
let parameters = ["sourceMapping": [
    [
      "from": [
        "tableId": "string",
        "type": "table"
      ],
      "to": [
        "tableId": "string",
        "type": "table"
      ]
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.sigmacomputing.com/v2/reports/reportId/swapSources")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```