Hi I am trying to execute below ways to run the POST call in power shell
option 1:
$Body="{ \`"cartItem\`" : {\`"sku\`" : \`"RG1219013\`", \`"qty\`" : \`"1\`", \`"quoteId\`" : \`"QRAeZdoFbieEWHjrRs5X0G1tHRE4el30\`" }}"
option 2:
$Body=@"
{ \"cartItem\" : {\"sku\" : \"RG1219013\", \"qty\" : \"1\", \"quoteId\" : \"QRAeZdoFbieEWHjrRs5X0G1tHRE4el30\" }}
"@
option3 :
$Body = @{
cartItem =
{
sku = 'RG1219013'
qty = '1'
quoteId = 'QRAeZdoFbieEWHjrRs5X0G1tHRE4el30'
}
}
$Json = (ConvertTo-Json $Body)
Execute:
$Header = @{ "Content-Type" = "application/json" }
Invoke-RestMethod -Method Post -Body $Body -Uri $UriAddtoCart -Header $Header
In option 1 and option 2 I am getting Bad request (400) and option 3 it's internal error (500)
Below jason respond successfully through postman
{
"cartItem" :
{
"sku" : "RG1219013",
"qty" : "1",
"quoteId" : "QRAeZdoFbieEWHjrRs5X0G1tHRE4el30"
}
}
Is there anything missing here?
Content-Typeheader is there@sign aftercartItem =in option 3 (this way you assign it a function), Thus:cartItem = {...should be:cartItem = @{...(check the actual content of the$Jsonfile)