I have been reading through these forums and finding a lot of help regarding API request. So far I'm able to request my API token via PS and use it for device management!
I'm fairly new to using API calls in PS and I can't seem to get around renaming a device. I' almost certain the issue is with how I'm using the -Body portion of the PS code.
Here is what I have so far:
#ALLOWS USER INPUT OF DEVICE NAME
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Device Rename'
$msg = 'Enter New Device Name:'
$Input = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
$Header2 = @{}
$Header2["Authorization"] = "Bearer " + $Token
try
{
$response2 = Invoke-restmethod -ContentType "application/json" -Uri https://$MCFQDN/mobicontrol/api/devices/$DevID/actions -Method POST -Headers $Header2 -Body {\"Action\": \"Rename\",\"Name\" : \"$Input\"}
}
catch
{
$($_.Exception.Message)
}
As stated, I think the -Body section is where I'm failing, not sure how to convert the curl request to a body in PowerShell.
Greatly appreciate any help!