Powershell API POST /devicegroups/{path}/members

C
Cory
Cennox

I have a script i am trying to get working, which is designed to move a specific device ID to a specific virtual group. I have several other API methods working properly in power-shell, but the POST /devicegroups/{path}/members is not wanting to play nice.

Below is my redacted code:

6 years ago
SOTI MobiControl
ANSWERS
TB
TJ Bukoski
6 years ago

I can see in the code that you are adding the group path to the body. But you are not supposed to do that with this API. The Group Path goes in the URL, which you are doing, but you are also putting it in the body which is unnecessary.

You are getting your error because the Group path is not a valid device ID.

The body just needs an array of device IDs only.

C
Cory
6 years ago

The group-path was removed, but the same error is still occurring. I am currently only passing the deviceID

adjusted Code:

Invoke-restmethod : {
"$type": "ErrorDetails",
"ErrorCode": 0,
"Message": "Contract validation failed",
"Data": [
"deviceIds: Error parsing value"
],
"HelpLink": null
}

SG
Sascha Gröger
6 years ago

i have the same Problem, of course with the same result. Any Solutions?

S
Scott
6 years ago

Sorry for the late reply, haven't been on the board much lately...

"DeviceIds" is just the parameter name.  It's not to be included as part of the parameter.  You're effectively just sending a JSON array of values in the request body:

["8867948f33f105010017110522502717","f375db664e6b0501d6edbcfe56d86559"]

The easiest way to figure out the correct usage is to use the api page and open a devtools window so you can see exactly what is being submitted in the request.

ML
Mattias Lundgren
2 years ago

This is what you have to do in PowerShell in order for this "non" name/value array to be accepted by MobiControl:

$MCFQDN #defined elsewhere

$Token #defined elsewhere

$FolderName = "Sub\Folders\Siblings"
$tablets = Get-MobiControlDevices -MCFQDN $MCFQDN -Token $Token -Path "Your root folder" -FolderName $FolderName -Take 2000

$Devices = $null
$counter = 0

foreach($tablet in $tablets)
{
    if($tablet.DeviceId -ne $null)
    {
        $DeviceId = $tablet.DeviceId
        if($counter -eq 0)
        {
            $Devices += "[  `"$DeviceId`""
        }
        else
        {
            $Devices += ",  `"$DeviceId`""
        }
        $counter++
    }
}
$Devices += "]" #add trailing

#Turns into this if you have two devices in the $FolderName -> "[  \"5cac3dbce85f\",  \"48bce121dc04\"]"

$Devices #"print out the devices for visual verification