Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否可以通过编程方式创建报表或将报表链接到Azure数据存储_Javascript_Azure_Powerbi_Powerbi Embedded_Powerbi Api - Fatal编程技术网

Javascript 是否可以通过编程方式创建报表或将报表链接到Azure数据存储

Javascript 是否可以通过编程方式创建报表或将报表链接到Azure数据存储,javascript,azure,powerbi,powerbi-embedded,powerbi-api,Javascript,Azure,Powerbi,Powerbi Embedded,Powerbi Api,我想使用PowerBIRESTAPI从我的NodeJS后端将报表连接到azure表存储 让我们举一个基本的例子: 我已经创建了一个报告,并使用Power BI Desktop手动将其连接到Azure表 现在我想复制此报告,但将其源更改为另一个Azure表存储(相同的数据结构,仅值更改) 我认为如何进行: 克隆报告 克隆数据集 更新数据集参数(放置新的Azure表凭据) 将克隆的报告参数更新到新的更新数据集 1。我可以用 对于2:我不知道如何使用powerrestapi复制数据集(我应该创建新的数

我想使用PowerBIRESTAPI从我的NodeJS后端将报表连接到azure表存储

让我们举一个基本的例子:

我已经创建了一个报告,并使用Power BI Desktop手动将其连接到Azure表

现在我想复制此报告,但将其源更改为另一个Azure表存储(相同的数据结构,仅值更改)

我认为如何进行:

  • 克隆报告
  • 克隆数据集
  • 更新数据集参数(放置新的Azure表凭据)
  • 将克隆的报告参数更新到新的更新数据集
  • 1。我可以用

    对于2:我不知道如何使用powerrestapi复制数据集(我应该创建新的数据集吗?)

    对于3:我发现了这一点,但是没有太多关于如何格式化body请求的细节

    对于4:

    是否可以自动将连接的PBI数据集设置为Azure表存储


    还有其他方法吗?

    克隆报表API将创建新报表,但它将位于同一数据集上。若要使用自己的数据集生成新报表,必须使用重新发布。您还可以使用下载原始报告。从头开始创建数据集要困难得多——创建所有表、它们的模式、关系、数据源和许多其他细节。你可以用电脑来做。如果这样做,则可以使用将报表重新绑定到新数据集

    当数据源为Azure Table时,我不知道body请求的确切模式。下面是一个PowerShell示例,说明如何对SQL Server数据源执行此操作:

    Import-Module MicrosoftPowerBIMgmt
    
    # Fill these ###################################################
    $workspaceName = "Awesome Reports"
    $datasetName = "Awesome Report"
    $sqlDatabaseServer = "mycompany.database.windows.net"
    $sqlDatabaseName = "CompanyData"
    $username = "user@example.com"
    $password = "strong password" | ConvertTo-SecureString -asPlainText -Force
    ################################################################
    
    
    $credential = New-Object System.Management.Automation.PSCredential($username, $password)
    Connect-PowerBIServiceAccount -Credential $credential | Out-Null
    $workspace = Get-PowerBIWorkspace -Name $workspaceName
    $dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $datasetName
    $datasource = Get-PowerBIDatasource -WorkspaceId $workspace.Id -DatasetId $dataset.Id
    
    # Construct url
    $workspaceId = $workspace.Id
    $datasetId = $dataset.Id
    $datasourceUrl = "groups/$workspaceId/datasets/$datasetId/datasources"
    
    # Call the REST API to get gateway Id, datasource Id and current connection details
    $datasourcesResult = Invoke-PowerBIRestMethod -Method Get -Url $datasourceUrl | ConvertFrom-Json
    
    # Parse the response
    $datasource = $datasourcesResult.value[0]
    $gatewayId = $datasource.gatewayId
    $datasourceId = $datasource.datasourceId
    $sqlDatabaseServerCurrent = $datasource.connectionDetails.server
    $sqlDatabaseNameCurrent = $datasource.connectionDetails.database
    
    # Construct url for update
    $datasourePatchUrl = "groups/$workspaceId/datasets/$datasetId/Default.UpdateDatasources"
    
    # create HTTP request body to update datasource connection details
    $postBody = @{
      "updateDetails" = @(
       @{
        "connectionDetails" = @{
          "server" = "$sqlDatabaseServer"
          "database" = "$sqlDatabaseName"
        }
        "datasourceSelector" = @{
          "datasourceType" = "Sql"
          "connectionDetails" = @{
            "server" = "$sqlDatabaseServerCurrent"
            "database" = "$sqlDatabaseNameCurrent"
          }
          "gatewayId" = "$gatewayId"
          "datasourceId" = "$datasourceId"
        }
      })
    }
    
    $postBodyJson = ConvertTo-Json -InputObject $postBody -Depth 6 -Compress
    
    # Execute POST operation to update datasource connection details
    Invoke-PowerBIRestMethod -Method Post -Url $datasourePatchUrl -Body $postBodyJson
    
    您可能可以使用查看原始数据集的外观,并更新上面的示例。但是,您可以使用参数指定数据源,而不是使用此API,这样您就可以使用相同的更新参数API重定向数据源

    如果数据源的凭据存储在服务中,您可能需要,例如:

    Import-Module MicrosoftPowerBIMgmt
    
    # Fill these ###################################################
    $workspaceName = "Awesome Reports"
    $datasetName = "Awesome Report"
    $sqlDatabaseServer = "mycompany.database.windows.net"
    $sqlDatabaseName = "CompanyData"
    $username = "user@example.com"
    $password = "strong password" | ConvertTo-SecureString -asPlainText -Force
    ################################################################
    
    $credential = New-Object System.Management.Automation.PSCredential($username, $password)
    Connect-PowerBIServiceAccount -Credential $credential | Out-Null
    $workspace = Get-PowerBIWorkspace -Name $workspaceName
    $dataset = Get-PowerBIDataset -WorkspaceId $workspace.Id -Name $reportName
    $workspaceId = $workspace.Id
    $datasetId = $dataset.Id
    $datasources = Get-PowerBIDatasource -WorkspaceId $workspaceId -DatasetId $datasetId
    
    foreach($datasource in $datasources) {
      $gatewayId = $datasource.gatewayId
      $datasourceId = $datasource.datasourceId
      $datasourePatchUrl = "gateways/$gatewayId/datasources/$datasourceId"
      Write-Host "Patching credentials for $datasourceId"
    
      # HTTP request body to patch datasource credentials
      $userNameJson = "{""name"":""username"",""value"":""$sqlUserName""}"
      $passwordJson = "{""name"":""password"",""value"":""$sqlUserPassword""}"
    
      $patchBody = @{
        "credentialDetails" = @{
          "credentials" = "{""credentialData"":[ $userNameJson, $passwordJson ]}"
          "credentialType" = "Basic"
          "encryptedConnection" =  "NotEncrypted"
          "encryptionAlgorithm" = "None"
          "privacyLevel" = "Organizational"
        }
      }
    
      # Convert body contents to JSON
      $patchBodyJson = ConvertTo-Json -InputObject $patchBody -Depth 6 -Compress
    
      # Execute PATCH operation to set datasource credentials
      Invoke-PowerBIRestMethod -Method Patch -Url $datasourePatchUrl -Body $patchBodyJson
    }
    

    感谢回复,我已经有了一个pbix文件并创建了参数,所以我只需更改参数值,即azure表存储名称。我能用powershell做到吗