Updating a Sublist
During update operations, lines of a keyed sublist are updated if the line contains matching keys, and the remaining lines from the request are added. For non-keyed sublists, the lines are always appended to the ones that are already present on the sublist. The following examples show PATCH operations upon a sublist. Key 1 and Key 2 indicate the field ID and value, respectively.
Request Body – Patch Operation
PATCH .../myrecord/100
{
"body1": "replaced body text 1",
"sublist" : {
"items" : [
{ "key1": "a", "key2": "1", "col": "replaced line 1" },
{ "key1": "b", "key2": "2", "col": "replaced line 2" }
]
},
"unkeyedsublist" : {
"items" : [
{ "col": "inserted line 1" },
{ "col": "inserted line 2" }
]
}
}
Response – Post State
Response:
204 No Content
Post State:
{
"body1": "replaced body text 1",
"body2": "previous body text 2",
"sublist" : {
"items" : [
{ "key1": "a", "key2": "1", "col": "replaced line 1" },
{ "key1": "b", "key2": "2", "col": "replaced line 2" },
{ "key1": "X", "key2": "0", "col": "previously present line 0" },
]
},
"unkeyedsublist" : {
"items" : [
{ "col": "previously present line 1" },
{ "col": "previously present line 2" },
{ "col": "previously present line 0" },
{ "col": "inserted line 1" },
{ "col": "inserted line 2" },
]
}
}
Keyed sublist lines are updated if the key matches, otherwise, a new line is created (in other words, sublist lines are merged). All lines of non-keyed sublists are added.
Request Body – Nullifying a Sublist
PATCH .../myrecord/100
{
"body1": "replaced body text 1",
"sublist" : {
"items" : null
}
}
{
"body1": "replaced body text 1",
"sublist" : null
}
Response – Post State
Response:
204 No Content
Post State:
{
"body1": "replaced body text 1",
"body2": "previous body text 2",
"sublist" : {
"items" : []
},
"unkeyedsublist" : {
"items" : [
{ "col": "previously present line 1" },
{ "col": "previously present line 2" },
{ "col": "previously present line 0" },
]
}
}
Keyed as well as non-keyed sublist lines are replaced. If the sublist is mandatory, it is expected that the operation fails.