title: Set report data source and credentials on Power BI Report Server through REST API to establish a scheduled refresh
body: <p>My task is the following: using the Power BI Report Server (PBIRS) <a href="https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0" rel="nofollow noreferrer">REST API</a>, upload an embedded report (embedded meaning that the data model is integrated in the report itself - a simple import from an SQL Server database, hence no live connection or DirectQuery etc.) to PBIRS, set the credentials (ConnectionString, Windows Authentication username and password) to access the data source (the database) and set up a daily scheduled refresh. </p>
  
  <p>With a Powershell script I'm able to upload the report with no problem, however complications arise when I try to set the credentials to the data source. Here is the code I currently have to accomplish this:</p>
  
  <pre><code>$payload0 = 
  '
  {
      "Name": "Data Source test",
      "Description": "string",
      "Path": "/Valid/Path",
      "Type": "DataSource",
      "Hidden": false,
      "Size": 0,
      "ModifiedBy": "string",
      "ModifiedDate": "2020-01-13T15:51:04Z",
      "CreatedBy": "string",
      "CreatedDate": "2020-01-13T15:51:04Z",
      "IsFavorite": false,
      "IsEnabled": true,
      "ConnectionString": "valid.connection\\string",
      "DataModelDataSource": {
        "AuthType": "Windows",
        "SupportedAuthTypes": [
          "Windows"
        ],
        "Kind": "SQL",
        "ModelConnectionName": "string",
        "Secret": "",
        "Type": "Import ",
        "Username": "myUserName"
      },
      "DataSourceSubType": "DataModel",
      "DataSourceType": "SQL",
      "IsOriginalConnectionStringExpressionBased": false,
      "IsConnectionStringOverridden": false,
      "CredentialRetrieval": "prompt",
      "CredentialsByUser": {
        "DisplayText": "someText",
        "UseAsWindowsCredentials": true
      },
      "CredentialsInServer": {
        "UserName": "myUserName",
        "Password": "myPassword",
        "UseAsWindowsCredentials": true,
        "ImpersonateAuthenticatedUser": true
      },
      "IsReference": false
    }
  '
  
  $restApiUri = $ReportPortalUri + "/api/v2.0/DataSources"
  
  Invoke-RestMethod -Uri $restApiUri -Method Post -Body $payload0 -ContentType "application/json" -UseDefaultCredentials -UseBasicParsing -Verbose
  </code></pre>
  
  <p>After running the code I get a <code>201 Created</code> response JSON that indicates the successful creation of the data source and its access credentials. If I check on the <code>Manage</code> pane of the report on PBIRS <em>I don't see any changes made to the data sources.</em></p>
  
  <p>My next step was to set the credentials manually by entering my username and password on the report server and then executing the following code to set up a scheduled refresh:</p>
  
  <pre><code>$payload1 = 
  '
  {
      "ParameterValues":[ 
  
      ],
      "Description":"testSchedule",
      "CatalogItemPath":"/Valid/Path",
      "EventType":"DataModelRefresh",
      "Schedule":{ 
          "Definition":{ 
              "EndDate":"0001-01-01T00:00:00Z",
              "StartDateTime":"2019-01-15T02:00:00Z",
              "EndDateSpecified":false,
              "Recurrence":{ 
                  "DailyRecurrence": { 
                  "DaysInterval":1
                  }
              }
          }
      }
  }
  '
  
  $restApiUri = $ReportPortalUri + "/api/v2.0/CacheRefreshPlans"
  
  Invoke-RestMethod -Uri $restApiUri -Method Post -Body $payload1 -ContentType "application/json" -UseDefaultCredentials -UseBasicParsing -Verbose
  </code></pre>
  
  <p>Running this code results in the successful creation of the scheduled refresh given that I set up the credentials to the data source manually beforehand.</p>
  
  <p>So my question in short: how to set up the credentials (Windows Authentication and username/password) of a data source (the SQL Server connection defined by a valid ConnectionString) with the PBIRS REST API?</p>
  
  <p>Any help would be appreciated! </p>