流数据集中的错误请求(错误#400)

时间:2017-05-12 14:24:17

标签: powershell powerbi

我使用Powershell脚本每分钟将数据上传到PowerBI中的流式数据集(使用Windows任务计划程序安排)。 我挣扎于奇怪的错误,这似乎没有改变任何东西。

这是我的代码:

function invokeRest()
{  


$endpoint = "https://api.powerbi.com/beta/..."

$query = @(Invoke-Sqlcmd -Query "select * from LS.dbo.live_Holdbacks;" -ServerInstance $env:computername)

$RetArray = @()

Foreach ($row in $query) {    
      $payload = @{
            "id" = $row.LiveHoldbackID
            "RefreshDate" = $row.RefreshDate.ToString("HH:mm")
            "CreatedBy" = $row.CreatedBy
            "Campaign Code" = $row.CampaignCode 
            "Campaign Description" = $row.CampaignDescription
            "Comment" = $row.Comment 
            "Customer Number" = $row.CustomerNumber 
            "Country" = $row.Country
            "holdback" = $row.holdback
            "upselling" = $row.upselling 

      }
      $RetArray += $payload
}

Write-Host (ConvertTo-Json @($RetArray));
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($RetArray)) -Verbose

}


function ClearDataset([string]$authToken)
{
    Clear-PBITableRows -authToken $authToken -dataSetName "DEV_live_holdbacks_no_History_1min" -tableName "RealTimeData" -Verbose 
}


Import-Module -Name PowerBIPS

$authToken = Get-PBIAuthToken -ClientId "...." -Credential (new-object System.Management.Automation.PSCredential("......",(ConvertTo-SecureString -String "...." -AsPlainText -Force)))
$group = Get-PBIGroup -authToken $authToken -name "..."
Set-PBIGroup -id $group.id
$dataSets = Get-PBIDataSet -authToken $authToken -name "DEV_live_holdbacks_no_History_1min" -includeTables -Verbose
#ClearDataset $authToken

    try {
        ClearDataset $authToken
        invokeRest 
    }
    catch {
        Write-Host 'Sth goes bad'
        Write-Host $_
        # do something with $_, log it, more likely
    }

API信息直接来自PowerBI,每个网址都可以,我在控制台中获得的所有内容都是:

The remote server returned an error: (400) Bad Request.

它突然停止工作......任何人都知道如何处理它?<​​/ p>

1 个答案:

答案 0 :(得分:1)

我想出来了!问题与其中一个字段有关 - 它的类型设置为Number,并且传入了字符串。