2017-09-13 52 views
0

我想用PowerShell腳本使用POST方法刷新電源bi數據集,但不斷收到關於媒體類型的錯誤,所以不知道該怎麼辦在這裏做。只是好奇,如果別人有任何解決方案。先謝謝您的幫助!!遠程服務器返回一個錯誤:(415)PowerBI數據刷新API調用不支持的媒體類型

請詳見該源代碼

https://github.com/Azure-Samples/powerbi-powershell/blob/master/manageRefresh.ps1

Poweshell error snapshot

# This sample script calls the Power BI API to progammtically trigger a refresh for the dataset 
# It then calls the Power BI API to progammatically to get the refresh history for that dataset 
# For full documentation on the REST APIs, see: 
# https://msdn.microsoft.com/en-us/library/mt203551.aspx 

# Instructions: 
# 1. Install PowerShell (https://msdn.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell) and the Azure PowerShell cmdlets (https://aka.ms/webpi-azps) 
# 2. Set up a dataset for refresh in the Power BI service - make sure that the dataset can be 
# updated successfully 
# 3. Fill in the parameters below 
# 4. Run the PowerShell script 

# Parameters - fill these in before running the script! 
# ===================================================== 

# An easy way to get group and dataset ID is to go to dataset settings and click on the dataset 
# that you'd like to refresh. Once you do, the URL in the address bar will show the group ID and 
# dataset ID, in the format: 
# app.powerbi.com/groups/{groupID}/settings/datasets/{datasetID} 

$groupID = " FILL ME IN " # the ID of the group that hosts the dataset. Use "me" if this is your My Workspace 
$datasetID = " FILL ME IN " # the ID of the dataset that hosts the dataset 

# AAD Client ID 
# To get this, go to the following page and follow the steps to provision an app 
# https://dev.powerbi.com/apps 
# To get the sample to work, ensure that you have the following fields: 
# App Type: Native app 
# Redirect URL: urn:ietf:wg:oauth:2.0:oob 
# Level of access: all dataset APIs 
$clientId = " FILL ME IN " 

# End Parameters ======================================= 

# Calls the Active Directory Authentication Library (ADAL) to authenticate against AAD 
function GetAuthToken 
{ 
     $adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll" 

     $adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" 

     [System.Reflection.Assembly]::LoadFrom($adal) | Out-Null 

     [System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null 

     $redirectUri = "urn:ietf:wg:oauth:2.0:oob" 

     $resourceAppIdURI = "https://analysis.windows.net/powerbi/api" 

     $authority = "https://login.microsoftonline.com/common/oauth2/authorize"; 

     $authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority 

     $authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto") 

     return $authResult 
} 

# Get the auth token from AAD 
$token = GetAuthToken 

# Building Rest API header with authorization token 
$authHeader = @{ 
    'Content-Type'='application/json' 
    'Authorization'=$token.CreateAuthorizationHeader() 
} 

# properly format groups path 
$groupsPath = "" 
if ($groupID -eq "me") { 
    $groupsPath = "myorg" 
} else { 
    $groupsPath = "myorg/groups/$groupID" 
} 

# Refresh the dataset 
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes" 
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method POST -Verbose 

# Check the refresh history 
$uri = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$datasetID/refreshes" 
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET -Verbose 
+0

您是否可以使用您遇到此問題的代碼更新該問題? – Persistent13

+0

@ Persistent13剛剛更新.. –

+0

根據我在[API參考](https://msdn.microsoft.com/en-us/library/mt203567.aspx#request)中看到的此Url的請求應該是GET不是POST。如果你改變它的工作? – Persistent13

回答

0

我經歷了這個確切的問題就來了。

你基本上是試圖從不能被刷新的數據集返回刷新信息(例如,直接查詢數據集或內置指標數據集)

您需要可以添加-ErrorAction SilentlyContinue

或包裹的數據集刷新API調用在這樣一個循環:

$ =數據集調用,RestMethod -uri $ URI -headers $ authHeader - 方法GET

foreach($dataset in $datasets.value) 
{ 
    if($dataset.isRefreshable -eq $true) 
    { 
     #Build API String 
     $uri2 = "https://api.powerbi.com/v1.0/$groupsPath/datasets/$($dataset.id)/refreshes" 
     #Return refresh info for each dataset 
     $refreshes = Invoke-RestMethod -Uri $uri2 -Headers $authHeader -Method GET 
    } 
} 
相關問題