如果我尝试通过 Microsoft 合作伙伴 API 检索客户的所有订阅,我只会收到 http 错误 500。我们是直接 Microsoft 合作伙伴,我可以通过
Get-PartnerCustomerSubscription
PowerShell 命令获取这些订阅。
我的代码如下所示:
$CustomerId = "CUSTOMERIDOFCUSTOMERINCSPPORTAL"
$Headers = @{
"Authorization" = "Bearer $($PartnerRefreshToken)"
"Accept" = "application/json"
}
$SubsUri = "https://api.partnercenter.microsoft.com/v1/customers/$CustomerId/subscriptions"
$SubsUriResponse = Invoke-RestMethod -Headers $Headers -Uri $SubsUri -Method GET
但我只得到这个一般错误:
Invoke-RestMethod : { "statusCode": 500, "message": "Internal server error", "activityId": "73e5479e-0f8c-4ecd-a26f-055ac17e124c" }
At line:1 char:20
+ ... iResponse = Invoke-RestMethod -Headers $Headers -Uri $SubsUri -Method ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
我尝试查阅 Microsoft API 文档,但没有找到任何答案,而且我似乎无法确定我的请求格式是否不正确。
我再次尝试,错误仍然存在。然后我将标题更改为: $PartnerAuthHeaders = @{Authorization = ("Bearer {0}" -f $newPartnerToken.AccessToken) } 并切换到使用 AccessToken 而不是 90 天的刷新令牌,现在它可以工作了: