首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于在PowerShell中更新设备组的Soti MobiControl应用编程接口调用

用于在PowerShell中更新设备组的Soti MobiControl应用编程接口调用
EN

Stack Overflow用户
提问于 2021-11-07 07:15:12
回答 1查看 98关注 0票数 0

我正在尝试使用引用ID进行API调用以更新每个循环中的一个设备组。我可以获取令牌,但在使用PUT更新设备组时遇到问题。这是我到目前为止尝试过的:

代码语言:javascript
复制
$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.
EN

回答 1

Stack Overflow用户

发布于 2021-11-15 15:21:53

基于api页面(https://FQDN/MobiControl/api)上的简短测试。如果我不用单引号或双引号引用customAttributeValue值本身,我会收到同样的“customAttributeValue: Error parsing value”错误。考虑到这一点,尝试修改您的$groupname变量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69870454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档