I Want to make a Post request in InvokeRestMethod.
Below is the body parameter i used to post content to Body
Expected parameter type is string for databaseName,password,roleName,databaseName.
Expected parameter type is stringarray for roles
My declaration for roles is not in stringarray type , it is being passed as json type i guess. please help in resolving below errors
$body = @{
databaseName='admin'
password= 'changeme123'
roles = {databaseName="sales";roleName="read"} | Out-String
username= 'sampleuser'
}
$json = $body | ConvertTo-Json
Invoke-RestMethod -Method POST -Uri $getProjectUri -Headers @{Authorization = "Basic $base64AuthInfo"} -Credential $credential -ContentType "application/json" -Body $json
Error: Invoke-RestMethod : {"detail":"Received JSON for the roles attribute does not match expected
format.","error":400,"errorCode":"INVALID_JSON_ATTRIBUTE","parameters":["roles"],"reason":"Bad Request"}
At C:\Users\xxxxxx\powershellscript\getusers2.ps1:40 char:3
+ Invoke-RestMethod -Method POST -Uri $getProjectUri -Headers @{Autho ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand