title: How to update a data source via the API
body: <p>I'm using a mix of the powershell powerbi management library and the rest api to update a datasource. (as documented here - <a href="https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/updatedatasourcesingroup#datasourceconnectiondetails" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/updatedatasourcesingroup#datasourceconnectiondetails</a>)</p>
  
  <p><code>https://api.powerbi.com/v1.0/myorg/groups/{0}/datasets/{1}/Default.UpdateDatasources</code> to update a data source. I'm passing in the workspace id for {0} and the dataset ID for {1}.</p>
  
  <pre><code>$datasets = Get-PowerBIDataset -WorkspaceId $workspaceObj.Id
  foreach($dataset in $datasets)
  {
      $DatasetId = $dataset.Id.Guid
  
      $json = 
  @'
  {{
      "updateDetails": [{{
              "datasourceSelector": {{
                  "datasourceType": "AnalysisServices",
                  "connectionDetails": {{
                      "server": "{0}",
                      "database": "{1}"
                  }}
              }},
              "connectionDetails": {{
                  "server": "{0}",
                  "database": "{1}"
              }}
          }}
      ]
  }}
  '@
      $json = [string]::Format($json, $AasServer, $modelName)
      $apiDatasetUrl = [string]::Format('https://api.powerbi.com/v1.0/myorg/groups/{0}/datasets/{1}/Default.UpdateDatasources',$workspaceObj.Id , $DatasetId)
      Invoke-RestMethod -Headers $headers  -Method 'Post' -Body $json -Uri $apiDatasetUrl -ContentType 'application/json'
  }
  </code></pre>
  
  <p>This results in a 404 error:</p>
  
  <blockquote>
    <p>Dataset {guid} is not found</p>
  </blockquote>
  
  <p>What am I doing wrong? I cannot understand how the dataset cannot be found, when the guid comes from the Power BI api.</p>
  
  <p>I've also tried including the "datasourceId" and the "gatewayId" in the json body, but this does not have an effect.</p>