Analysis of Replace a Node API
Use Discussion notes to capture meeting items, assign owners, and track actions and decisions.
Date | Item | Owner | Notes | Relevant Links |
---|---|---|---|---|
Aug 9, 2024 |
| @someone | Action |
|
Problem Statement
The Replace Node Leaves API can only perform a replace operation on one data node at a time and in order to perform this request the user needs to provide the following parameters as part of the request:
the parent node xpath of the node being replaced
the JSON/XML payload containing the new data which will replace the existing data.
Scenario 1: API accepts new list items
If a replace operation is performed on a list node, where an already existing list item is being replaced, then in this scenario a user induced error can take place where the user can send a new list item as part of the payload.
This results in a 200-response code being returned to the user but with a partial replace operation.
Because when the data is verified after the replace operation is executed, it is seen that the data of existing list item is replaced, which is the expected behavior. But the data of the new list item is not added under the list node.
But since the API returns a 200-response code, it could create a false sense of security for the user that the request executed successfully, where in fact only a partial operation took place in the database.
A more detailed explanation with examples is as follows:
1. In the following data, the node titled “Matilda",
under the list named “books",
is to be replaced.
2. In order to do so the correct parent node xpath and JSON payload would be as follows:
3. API accepts extra/new list elements as part of request
If the user modifies an existing list item and along with that adds a new list item in the payload then once the request is executed the user receives a 200-response code. But upon verifying the data after the request is executed it is seen that only
4. The data queried after the above replace operation is executed is as follows:
It can be seen that only the existing list item, i.e. title: Matilda
is replaced. Whereas the newly added list item with title: Book 2
is not added but user received a 200-response code.
Expected Behavior
This is a user error as request is in itself wrong, because it tries to add a new list item to a list.
CPS provides a separate endpoint to Add a list element
So, such a scenario should be handled by throwing an exception from the API instead of returning a successful response.
Add support to Add list elements using Replace a node API
Throw appropriate error message when a non-existing list item is sent as part of the payload
Proposed/Accepted Solutions
WIP