I've been trying (and failing for hours) to convert this cURL script into PowerShell:
curl -X POST \
https://example.net \
-H 'Authorization: Bearer 1234567890' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"data": {
"MID": 33,
"DID": "66666666",
"CID": 10002,
"status": "ACTIVE",
"HID": "11"
}
}'
My PowerShell script looks like this - I suspect it's something to do with the double hash table I've created in $Body but I am really at a loss.:
.. script snipped for simplicity
$Body = @{
'data'= @{
'MID'= 33;
'DID'= "66666666";
'CID'=10002;
'status'="ACTIVE";
'HID'= "11"
}
}
$CurlArgument = '-X', 'POST',
'https://example.net',
'-H', 'Authorization: Bearer 1234567890',
'-H', 'Content-Type: application/json',
'-d',
$Body
$CURLEXE = 'C:\Windows\System32\curl.exe'
& $CURLEXE @CurlArgument
I get the following error message when it executes:
..."message":"Access not allowed","details":{"5011":"A JSONObject text must begin with '{' at 1 [character 2 line 1]"}}]}
I experimented with adding after $Body:
| ConvertTo-Json
but that then gives me this error:
Unexpected character ('d' (code 100)): was expecting double-quote to start field name
My $CurlArgument variable looks like this (which looks the same as the first cURL script):
-X
POST
https://example.net
-H
Authorization: Bearer 1234567890
-H
Content-Type: application/json
-d
{
"data": {
"CID": 10002,
"MID": 33,
"HID": "11",
"DID": "66666666",
"status": "ACTIVE"
}
}
As always, assistance would be greatly appreciated.
$Body
variable containing a[hashtable]
instance would not render as JSON text. That a hashtable doesn't automatically turn into a JSON string is indeed the crux of your problem. – mklement0 Nov 22 '18 at 4:01