Modifying a Custom Attribute on an device by API & PS

Solved Locked
NL
Nicolas LE BIHAN
SYSTEME U CENTRALE NATIONALE

I am trying to make an API call to update one device in using the reference ID. I am able to fetch token but having issue when using PUT to update the device. Here is what i tried so far:

### Call API

#Module and Configurations API
Import-Module -Name "F:\SOTI_API\Mod-MobiControl.psm1"
Set-TrustAllCertsPolicy

$Token = Get-MCToken
$MCFQDN = Get-MCFQDN

#Core script
$headers = @{}
$headers["Authorization"] = "Bearer " + $Token
$deviceId = "9c5c8e786faa050100171845214D2417"

$AttributeValue = @{}
$AttributeValue["customAttributeValue"] = "123"
$body = $AttributeValue | ConvertTo-Json


#PUT customAttributes Projet

$result = Invoke-restmethod -Uri "https://$MCFQDN/mobicontrol/api/devices/$deviceId/customAttributes/Projet" -ContentType "application/json" -Method PUT -Headers $headers -body $body

When trying to execute the above, getting below error:

Invoke-restmethod : { "$type": "ErrorDetails", "ErrorCode": 0, "Message": "Échec de validation du contrat", "Data": [ "customAttributeValue: Error parsing value" ], "HelpLink": null }
Au caractère Ligne:22 : 15
+ $result = Invoke-restmethod -Uri "https://$MCFQDN/mobicontrol/api/devices/$d ...

Any help is greatly appreciated.
 
4 years ago
SOTI MobiControl
ANSWERS
NL
Nicolas LE BIHAN
4 years ago

Hello,
I corrected my script as below, and it worked.

#Core script
$headers = @{}
$headers["Authorization"] = "Bearer " + $Token
$customAttributeValue = "123"
$body = $customAttributeValue | ConvertTo-Json

Solution
G
GKMOD@SOTI
4 years ago (edited 4 years ago)

Hi Nicolas,

Have you tested / executed the API on the following page (MobiControl REST API Reference) and if it worked?

https://[FQDN] /MobiControl/api

Below is an example.

The result.