powershell - Soti MobiControl API 调用以更新 PowerShell 中的设备组
问题描述
我正在尝试使用参考 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.
解决方案
基于 api 页面 (https://FQDN/MobiControl/api) 上的简短测试。如果我没有用单引号或双引号引用 customAttributeValue 值本身,我会收到相同的“customAttributeValue: Error parsing value”错误。考虑到这一点,尝试修改您的 $groupname 变量。
推荐阅读
- javascript - 将新功能分配给 ng-click 刷新后恢复
- c - 登录时没有匹配的二维字符串数组
- android - 为什么 JavaScript v8 引擎设计为每个进程只能初始化一次?
- python - 将 Python 转换为 R 时如何正确设置参数?
- javascript - Vue-router路由到错误的页面,链接必须在路径前添加'#'
- angular - 未收到应用程序的前台通知(Angular 和 NestJs)
- swiftui - 在 swiftUI 中获取当前登录的用户 Firebase
- typescript - Typescript 接口,对象数组的数组
- python - 尽管给出了路径,但无法执行 shell 脚本
- javascript - 如何递归地进行ajax调用,以检查服务是否可用