2013-10-01 85 views
0

因此,首先我对PowerShell相当陌生(在去年),现在我明白了很多,但现在API调用对我来说是新的。Powershell API Web服务调用

我已经弄清楚如何使用不需要任何值的Web调用进行API调用。或者那些不需要数值的数组。如:$ BSSPrincipalManagementWSP.ReadAccount(“1_V4-0119341”)

返回我想要的一切。但是如果我进入$ BSSPrincipalManagementWSP.UpdateAccountValues之类的网页调用中,第一个变量是账户外部ID,但所需的第二个变量是数组中的accountValues。

我已经试过这样的事情来完成它:

function Update-AccountValues 

(

    [string]$accountExternalId, 

    [array]$accountValues = @(Import-Csv -Path $ImportPath) 

) 

{ 

    $accountValues 

    $BSSPrincipalManagementWSP.UpdateAccountValues($accountExternalId, $accountValues) 

} 



Update-AccountValues "1_V4-0119341" 

,但我得到了以下错误:

Cannot convert argument "accountValues", with value: "System.Object[]", for  "UpdateAccountValues" to type "BSSPrincipalManagementNS.AccountValue[]": "Cannot convert value 

"@{Key=ScreenSaverTimeoutMinutes; Value=60}" to type "BSSPrincipalManagementNS.AccountValue". Error: "Cannot convert the "@{Key=ScreenSaverTimeoutMinutes; Value=60}" value of type 

"System.Management.Automation.PSCustomObject" to type "BSSPrincipalManagementNS.AccountValue"."" 

At C:\Users\Matt Bergeron\AppData\Local\Temp\ff88f967-9d7c-4f6f-a424-212298a69655.ps1:61 char:2 

+  $BSSPrincipalManagementWSP.UpdateAccountValues($accountExternalId, $accountValu ... 

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

+ CategoryInfo   : NotSpecified: (:) [], MethodException 

+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument 

我以为我传递“accountValue对象的数组”,因为它要求。

CSV文件中的所有内容都是2列,1列为键,另一列列为值。这些命名与OSS/BSS CHM文件的名称完全相同。

其他人能告诉我哪里出错了吗?任何帮助将非常感激。

回答

0

您的API预计值为特定类型BSSPrincipalManagementNS.AccountValue[]。您需要找到另一个API调用,您可以在其中创建BSSPrincipalManagementNS.AccountValue的实例并将它们放入数组中。然后用该数组调用原始API。

+0

就像我说过的,我对API调用非常陌生,你有什么建议在哪里寻找其他API来创建数组?谢谢您的意见。 – chamele0n

+0

@ chamele0n对不起,但我不知道这个API的任何东西。您可以联系创建Web服务的人以获取指向文档的指针吗? –