Webapi and post resquest

Hello,
I have a query that works with Postman
Postman body
{
“ObjectDN”: “toto”,
“AttributeName”: “Disabled”,
“Values”: [“1”]
}

I try in powershell

Powershell extract
$fullID = "toto"
function retire($fullID){
$json = @{ObjectDN=$fullID;AttributeName="Disabled";Values="1"}|ConvertTo-Json
$uri = $baseurl + '/Config/Write?apikey=' + $global:key
$statut = Invoke-RestMethod -Uri $uri -Body $json -Method POST -ContentType 'application/json'
if($statut.Result -eq $null){
return "error"
}else{
return $statut.Result
}

When I run it I have an error
« Invoke-RestMethod : {“Error”:“Unable to parse input document.”} »

I think the problem is the conversion of the line
“Values”: [“1”]
that works in Postman
but in powershell we can not use
I’m looking for a solution
Bests regards

Try generating your JSON like so:

$body = New-Object -TypeName PSObject -Property @{
    "ObjectDN" = "toto"
    "AttributeName" =  "Disabled"
    "Values" = @("1")
}

$jsonBody = $body | ConvertTo-Json

$jsonBody

Output:

{
    "AttributeName":  "Disabled",
    "Values":  [
                   "1"
               ],
    "ObjectDN":  "toto"
}

To point out a personal experience with one specific API that didn’t seem to like any carriage returns in the JSON body, I had to also use the -compress parameter of ConvertTo-JSON and also wrap the value with single quotes.

$JSON=@{Name=Value} | ConvertTo-JSON -compress
$Body='$($JSON)'
Invoke-RESTMethod -body $Body #missing URI/Header/Method of course

Hello
Thank you for yours answer I would test on my return from holidays
Yann