This issue I am having is that the Invoke-RestMethod doesn't seem to handle arrays within Arrays. I have the variable $addToBasket which is set up below.
$addToBasket = @{
LocationId= 1
ItemReference= (
"A-TTA-G",
"A-TTA-B+"
)
StartDateTime= (
"2014-11-19T09:00:00",
"2014-11-19T09:00:00"
)
Quantity= (
1,
1
)
BasketReferenceGuid= $basketRef
}
If you look at this variable in PS it looks as follows: PS H:> $addToBasket
Name Value
---- -----
Quantity {1, 1}
ItemReference {A-TTA-G, A-TTA-B+}
StartDateTime {2014-11-19T09:00:00, 2014-11-19T09:00:00}
BasketReferenceGuid 0ca311a5-4c8d-4a03-9149-cfd174b27c17
LocationId 1
Now I run the rest method and I've used fiddler to capture the result
Add to Basket
$addedForm = Invoke-RestMethod -Uri $env:USERDOMAIN"/Api/v1/BasketActivityProducts" -Method Post -Body $addToBasket -WebSession $Wsess
PS Response :
Invoke-RestMethod : {"Code":15,"Message":"The value 'System.Object[]' is not valid for DateTime.\nThe value 'System.Object[]' is not valid for Int32.\n","ResourceType":"ErrorObject"}
The fiddler logs reveal the following request being sent
Quantity=System.Object%5b%5d
&ItemReference=System.Object%5b%5d
&StartDateTime=System.Object%5b%5d
&BasketReferenceGuid=2377472a-93b7-44ac-a6d9-690d732e85c2
&LocationId=1
Does anyone know how to get round PS sending the arrays as (System.Object)?