我正在尝试使用引用ID进行API调用以更新每个循环中的一个设备组。我可以获取令牌,但在使用PUT更新设备组时遇到问题。这是我到目前为止尝试过的:
$Header1 = @{}
$Header1["Authorization"] = "Bearer " + $Token
try
{
#Using /devices to get the group level path as I am trying to update a customattribute on group level instead of each device
$response1 = Invoke-RestMethod -Uri "https://$MCFQDN/MobiControl/api/devices" -Headers $Header1
#Using /devicegroups for reference ID
$response2 = Invoke-RestMethod -Uri "https://$MCFQDN/MobiControl/api/devicegroups" -Headers $Header1
}
catch
{
$($_.Exception.Message)
}
foreach ($path1 in $response1)
{
foreach ($path2 in $response2)
{
if ($path1.Path -eq $path2.Path)
{
$refid = "referenceId:" + $path2.ReferenceId
#$refid = [System.Web.HttpUtility]::UrlEncode($refid) #tried encoding refid but no use
$uri = "https://$MCFQDN/MobiControl/api/devicegroups/$refid/customAttributes/{Custom_Attribute_Name}"
#This is the value for my Custom_Attribute_Name
$groupname = ($path2.Path).split('\')[-1]
$Body1 = @{}
$Body1["customAttributeValue"] = $groupname
# tried $Body1 = @{$groupname} but in vain
Invoke-RestMethod -Uri $uri -Method PUT -Body ($Body1 | ConvertTo-Json) -Headers $Header1 -ContentType "application/json"
}
}
}```
When trying to execute the above, getting below error:
*Invoke-RestMethod : {
"$type": "ErrorDetails",
"ErrorCode": 0,
"Message": "Contract validation failed",
"Data": [
"customAttributeValue: Error parsing value"
],
"HelpLink": null
}*
Any help is greatly appreciated.发布于 2021-11-15 15:21:53
基于api页面(https://FQDN/MobiControl/api)上的简短测试。如果我不用单引号或双引号引用customAttributeValue值本身,我会收到同样的“customAttributeValue: Error parsing value”错误。考虑到这一点,尝试修改您的$groupname变量。
https://stackoverflow.com/questions/69870454
复制相似问题