I am exploring PowerShell 7 and Invoke-RestMethod. I am struggling to find a solution on setting the proper syntax for -Body
In Postman is can do a POST /v3/search?count=true&offset=0&limit=2000, with a Body of:
{
“query”: {
“query”: “*”
},
“indices”: [
“roles”
],
“sort”: [
“name”
],
“includeNested”: false
}
I am using the $Form variable in my script with the -Body parameter
Call: $responseObj = Invoke-RestMethod -Headers $postHeaders -Body $Form -Method ‘POST’ -Uri $uploadURL
I have tried more than the below 3 attempts to set $Form.
$From =‘{
“query”: {
“query”: “*”
},
“indices”: [
“roles”
],
“sort”: [
“name”
],
“includeNested”: false
}’
$From =‘{
“query”: {
“query”: “*”
},
“indices”: [
“roles”
],
“sort”: [
“name”
],
“includeNested”: false
}’ | convertfrom-json
$Form = @{
query = ‘“query”: “*”’
indices = ‘roles’
‘sort’ = ‘name’
“includeNested”=‘false’
}
}
I receive a “400.0 Bad request syntax”, “The request could not be parsed.” If I run the line without -body, I receive a “400.1.0 Required data missing or empty”, “Required field "search" was missing or empty.”
I am new to the whole development role and would appreciate any insight/assistance.
Regards.