aaronengels / DattoRMM

A PowerShell module that connects to the Datto RMM API
GNU General Public License v3.0
64 stars 23 forks source link

Set-DrmmDeviceQuickJob fails when using single variable #9

Closed sovapatr closed 3 years ago

sovapatr commented 3 years ago

/v2/device/{deviceUid}/quickjob requires that the variables field be an array. If you pipe a single item array to ConvertTo-Json the returned json is no longer an array.

PS > $vars = @() + @{name = "timeout";value = 5}
PS > $vars | ConvertTo-Json -compress
{"value":5,"name":"timeout"}

It does work if you Call ConvertTo-Json directly though.

PS > ConvertTo-Json $vars -compress
[{"value":5,"name":"timeout"}]

So I believe the code should be something like this:

# Create quick job request
$quickJobRequest.Add('jobName',$jobName)
$jobComponent.Add('componentUid',$componentUid)
$variables = @() + $variables
$jobComponent.Add('variables',$variables)
$quickJobRequest.Add('jobComponent',$jobComponent)

# Convert to JSON
$Body = ConvertTo-Json $quickJobRequest -depth 3
aaronengels commented 3 years ago

You're right, the component variables should be passed as a JSON array. Thanks for the input, I'll make the changes in the next release :-)