Hello,
I’d like some advice on how to structure a payload.
We are modelling a delivery route. The route has stops and each stop has parcels. The stops do not exist as separate resources; they are merely items in an array within the route and do not have IDs. The order of the stops is of course very important. The parcels, however, do exist as separately-accessible resources and we want to carry some of the parcels’ data in the payload - so we’re going to use the “included” section of JSONAPI.
As I understand it, I shouldn’t just insert the parcels’ data into the main “attributes” section of the route (although it is tempting). Does this mean that I need to include a reference in the “metadata” of the items within the “included” section to relate them back to the stop?
This would lead to a payload like the following (two stops, three parcels - one parcel for the first stop and two at the second)…
{
"data": {
"type": "route",
"id": 123,
"attributes": {
"stops": [
{
"stopId": 1,
"address": "SNIP",
"instructions": "Leave by back door"
},
{
"stopId": 2,
"address": "SNIP"
}
]
}
},
"included": [
{
"type": "parcel",
"id": "AB123",
"attributes": {
"weight": "10Kg",
"highValue": false
},
"meta": {
"stopId": 1
}
},
{
"type": "parcel",
"id": "CD456",
"attributes": {
"weight": "5Kg",
"highValue": true
},
"meta": {
"stopId": 2
}
},
{
"type": "parcel",
"id": "EF789",
"attributes": {
"weight": "15Kg",
"highValue": false
},
"meta": {
"stopId": 2
}
}
]
}
It doesn’t look quite right to me. Thoughts welcomed.
J.