Hi guys,
I’m trying to create a StockMovement with Line Items through api.
The request looks like this:
{
"name": "test01",
"description": "test01",
"origin": {
"id": "1"
},
"destination": {
"id": "8a8280847bb2c8bb017bb5df9b1d0002"
},
"dateRequested": "10/19/2022",
"requestedBy": {
"id": "8a8280847bc0cedf017bc1af1e240001"
},
"lineItems": [
{
"quantityRequested": 4,
"sortOrder": 0,
"recipient": null,
"product": {
"id": "8a8280847bad6572017bad6a6d980003"
}
},
{
"quantityRequested": 8,
"sortOrder": 0,
"recipient": null,
"product": {
"id": "8a8280847bad6572017bad6a6dc00004"
}
}
]
}
But I got an error:
{
"errorCode": 400,
"errorMessage": "Validation error. Invalid stock movement:\n- Field error in object 'org.pih.warehouse.api.StockMovement' on field 'lineItems': rejected value [[{\"product\":{\"id\":\"8a8280847bad6572017bad6a6d980003\"},\"sortOrder\":0,\"quantityRequested\":4,\"recipient\":null},{\"product\":{\"id\":\"8a8280847bad6572017bad6a6dc00004\"},\"sortOrder\":0,\"quantityRequested\":8,\"recipient\":null}]]; codes [typeMismatch.org.pih.warehouse.api.StockMovement.lineItems,typeMismatch.lineItems,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [org.pih.warehouse.api.StockMovement.lineItems,lineItems]; arguments []; default message [lineItems]]; default message [Failed to convert property value of type 'org.codehaus.groovy.grails.web.json.JSONArray' to required type 'java.util.List' for property 'lineItems'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.codehaus.groovy.grails.web.json.JSONObject] to required type [org.pih.warehouse.api.StockMovementItem] for property 'lineItems[0]': no matching editors or conversion strategy found]\n",
"errorMessages": [
"Failed to convert property value of type org.codehaus.groovy.grails.web.json.JSONArray to required type java.util.List for property lineItems; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.codehaus.groovy.grails.web.json.JSONObject] to required type [org.pih.warehouse.api.StockMovementItem] for property lineItems[0]: no matching editors or conversion strategy found"
]
}
But when I try to create it without LineItems(empty array) it creates it successfuly.
Do you know what could the problem?
Does API not support creating StockMovement with LineItems included in it in one request?
Also I tried to call another api(~/stockmovenets/id/updateItems) call to create LineItems for already created Stockmovennt and it works but only if I set “product.id”: “productId” in JSON for LineItem object. But it fails when I pass product id as a json like: “product” : {“id”: “productId”}
Anyway, how can I properly create StockMovement with LineItems in it?
Thanks