I have the following logic that sets values on a json object ... then tries to convert to a json string, stuff into the Body of an HTTP request. When I attempt the POST the request fails because the body is empty. But the debug print that outputs the $widget just before I attempt the assignment to Body looks valid.
Code Looks like this:
$widget = (Get-Content './testdata/notification.json') | ConvertFrom-Json
Write-Output $widget.GetType();
Write-Output $sourcedata.GetType();
$widget.requestId = $sourcedata.requestId
$widget.status = "provisioned"
$widget.workspace.id = $sourcedata.workspace.id
$widget.workspace.isReadOnly = "false"
$widget.workspace.isOnDedicatedCapacity = $sourcedata.workspace.isOnDedicatedCapacity
$widget.workspace.name = $sourcedata.workspace.name
$widget.workspace.owners = $sourcedata.workspace.owners
# Convert to Json
$widget | ConvertTo-Json -Depth 5
Write-Output $widget
$params = @{
Uri = "http://localhost:7071/workspace/notification"
Method = "POST"
Headers = @{
'Authorization' = 'Bearer ' + $token
'Content-Type' = 'application/json'
}
'Body'= $widget
}
$notificationResult = Invoke-RestMethod @params
Any tips would be appreciated.
What's interesting is that when I try to print the object type of the widgets object just after I assign it all the values and convert to json, nothing comes back.
Write-Output $widget.GetType()
returns:
True False PSCustomObject System.Object
instead of something like:
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array