...
When a list is fetched using Get a node API then instead of returning a one list containing n-number of list nodesitems, the API returns n-lists containing one data node in each listJSON objects where each object contains one list item each.
For example: if there is a list named "Items" containing 10 items named Item 1, Item 2, ......, Item 10. Then when fetching this list is fetched using get a node API a total of 10 individual lists JSON objects are returned where each list object contains one Item, i.e. List 1→Item 1, List 2→ Item 2, ......., List 10→ Item 10.
...
Data Originally Stored
...
Child pages (Children Display) |
---|
depth | 1 |
---|
allChildren | false |
---|
style | |
---|
sort | title |
---|
first | 1 |
---|
sortAndReverse | title |
---|
|
Expand |
---|
Data Originally Stored Code Block |
---|
{
"book-store:bookstore": {
"bookstore-name": "Easons",
"categories": [
{
"code": "1",
"name": "Children",
"books": [
{
"title": "Matilda",
"lang": "English",
"price": 20
},
{
"title": "The Gruffalo",
"lang": "English",
"price": 15
}
]
}
]
}
} |
| Response when querying the list directly Code Block |
---|
[
{
"books": {
"title": "Matilda",
"lang": "English",
"price": 20
}
},
{
"books": {
"title": "The Gruffalo",
"lang": "English",
"price": 15
}
}
] |
| Expected Result Code Block |
---|
[
{
"books": [
{
"title": "Matilda",
"lang": "English",
"price": 20
},
{
"title": "The Gruffalo",
"lang": "English",
"price": 15
}
]
}
] |
| This behavior extends to list items stored under root node as well. So, this case needs to be taken into consideration as well | |
|
Initial setup to try the sample requests up ahead
...
When updating any data node, it's parent node xpath is provided as part of the update request. And the JSON payload contains the data of child node to be updated.
But if the JSON data of the parent node is provided due to a user error the parent nodes data can be sent as part of this the JSON payload and even then, then instead of failing , the request is successfully executed with partial update Where only the child data node is updated, and the parent data node is not updated.
Expand |
---|
Original JSON data: | JSON with updates | JSON data after update | Notes |
---|
Code Block |
---|
{
"code": 1,
"name": "Children",
"books": [
{
"title": "Matilda",
"lang": "English",
"authors": ["Roald Dahl"],
"editions": [1988, 2000],
"price": 20
}
]
} |
| Code Block |
---|
{
"code": 1,
"name": "Kids",
"books": [
{
"title": "Matilda",
"editions":
[1988, 2000, 2024],
"price": 25
}
]
} |
| Code Block |
---|
{
"code": "1",
"name": "Children",
"books": [
{
"title": "Matilda",
"lang": "English",
"authors": ["Roald Dahl"],
"editions":
[1988, 2000, 2024],
"price": 25
}
]
} |
It can be seen that the leaf data belonging to parent node i.e. code=1 is sent as part of JSON body. Where name is changed from Children to Kids And the fields editions and price, of child node, i.e. title=Matilda are modified. But after the request is executed only the child node is updated. | The expected behavior should be to throw an exception as the Update a node API requires parent node xpath to update any child data. Which in this case should be "/bookstore" because the request is also updating the node with key "code=1" This situation can mainly occur due to user error, where user provides updated parent data along with parent node xpath as part of the request.
| Curl request to replicate the scenario Code Block |
---|
curl --location --globoff --request PATCH 'http://localhost:8883/cps/api/v2/dataspaces/my-dataspace/anchors/bookstore/nodes?xpath=%2Fbookstore%2Fcategories[%40code%3D1]' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: ••••••' --data '{
"code": 1,
"name": "Kids",
"books": [
{
"title": "Matilda",
"editions":
[1988, 2000, 2024],
"price": 25
}
]
}' |
|
|
...
Expand |
---|
Original JSON data | JSON to be updated | Updated JSON data | Notes |
---|
Code Block |
---|
{
"categories": {
"code": "1",
"name": "Children",
"books": [
{
"title": "Matilda",
"lang": "English",
"price": 200,
"authors":["Roald Dahl"],
"editions": [1988,2000]
}
]
}
} |
| Code Block |
---|
{
"categories": {
"code": 1,
"name": "Kids",
"books": [
{
"title": "Matilda",
"price": 20,
"editions":
[1988, 2000, 2022]
}
]
}
} |
| Code Block |
---|
{
"categories": {
"code": "1",
"name": "Kids",
"books": [
{
"title": "Matilda",
"lang": "English",
"price": 200,
"authors": ["Roald Dahl"],
"editions": [1988,2000] }
]
}
} | The request is executed successfully but only a partial update takes place in the database. | | Curl request to replicate the scenario Code Block |
---|
curl --location --request PATCH 'http://localhost:8883/cps/api/v2/dataspaces/my-dataspace/anchors/bookstore/nodes?xpath=%2Fbookstore' --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: ••••••' --data '{
"categories": {
"code": 1,
"name": "Kids",
"books": [
{
"title": "Matilda",
"price": 20,
"editions":
[1988, 2000, 2022]
}
]
}
}' |
|
|
...