简体   繁体   English

远程服务器返回错误:(415)PowerBI Data Refresh API调用不支持的媒体类型

[英]The Remote Server returned an error : (415) Unsupported media type for PowerBI Data Refresh API Call

I am trying to refresh power bi dataset using POST method with PowerShell script, but keep getting an error about media type so not sure what to do here. 我正在尝试使用带有PowerShell脚本的POST方法来刷新power bi数据集,但始终会遇到有关媒体类型的错误,因此不确定在这里做什么。 Just curious if somebody else having any solution for this. 只是好奇是否有人对此有任何解决方案。 Thanks in advance for the help!! 先谢谢您的帮助!!

Please see this source code for more details... 请参阅此源代码以获取更多详细信息...

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

Poweshell错误快照

    # 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

I've came across this exact issue. 我遇到了这个确切的问题。

You are basically trying to return refresh info from a dataset that cannot be refreshed (Eg. A direct Query dataset or the builtin metrics datasets) 您基本上是在尝试从无法刷新的数据集中返回刷新信息(例如,直接查询数据集或内置指标数据集)

You need to either add -ErrorAction SilentlyContinue 您需要添加-ErrorAction SilentlyContinue

or wrap the dataset refresh API call in a loop like this: 或将数据集刷新API调用包装在这样的循环中:

$datasets = Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET $ datasets = Invoke-RestMethod -Uri $ uri -Headers $ authHeader -Method 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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(415)在asp.net中使用API​​的不支持的媒体类型 - The remote server returned an error: (415) Unsupported Media Type using API in asp.net HTTPWebRequest GET错误远程服务器返回错误:(415)不支持的媒体类型 - HTTPWebRequest GET error The remote server returned an error: (415) Unsupported Media Type System.Net.WebException:远程服务器返回错误:(415)UNSUPPORTED MEDIA TYPE - System.Net.WebException : The remote server returned an error: (415) UNSUPPORTED MEDIA TYPE 服务器返回的HTTP响应代码:415不支持的媒体类型 - Server returned HTTP response code: 415 Unsupported media type 向服务器发送数据时 HTTP 415 不支持的媒体类型客户端 - HTTP 415 Unsupported Media Type client when sending data to server 获取错误 415 - 获取 api 中不支持的媒体类型 - Getting error 415 - Unsupported media Type in fetch api 415不支持的媒体类型 - 415 Unsupported Media Type RestTemplate - 415 UNSUPPORTED_MEDIA_TYPE 错误 - RestTemplate - 415 UNSUPPORTED_MEDIA_TYPE Error 415 删除操作不支持的媒体类型错误 - 415 Unsupported media type error for DELETE Operation 415(不受支持的媒体类型) - 415 (Unsupported Media Type)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM