Virto Commerce modules v3.829.0 added support for partial updates for entities using PATCH endpoint.
New methods were added to platform API:
PATCH api/members/{id}
PATCH api/contacts/{id}
PATCH api/organizations/{id}
All of them receive a special json object that describes the operations performed on the fields.
Example JSON Patch Request
[
{ "op": "add", "path": "/newField", "value": "New Value" },
{ "op": "remove", "path": "/oldField" },
{ "op": "replace", "path": "/existingField", "value": "Updated Value" },
{ "op": "move", "from": "/tempField", "path": "/finalField" },
{ "op": "copy", "from": "/sourceField", "path": "/destinationField" },
{ "op": "test", "path": "/testField", "value": "Expected Value" }
]
add - to add an element to an array
remove - to remove an element from an array
replace - to change value in the field
More about at the article JsonPatch in ASP.NET Core web API | Microsoft Learn
For example, to update the member’s “MiddleName” field, such a request is sufficient:
[
{
"op": "replace",
"path": "/middleName",
"value": "Mishel"
}
]
To add new phone to the pones array (it is necessary to specify the index, it can be max as array size)
[
{
"op": "add",
"path": "/phones/0",
"value": "+79995558545"
}
]
To remove
[
{
"op": "remove",
"path": "/phones/1"
}
]
Also it possible to add a new object to object-arrays
[
{
"op": "add",
"path": "/addresses/1",
"value": {
"addressType": "BillingAndShipping",
"name": "ESP, Valencia, c/ Eucaliptus 10",
"organization": "",
"countryCode": "ESP",
"countryName": "Spain",
"city": "Valencia",
"postalCode": "44375",
"zip": null,
"line1": "c/ Eucaliptus 10",
"line2": "pta. 10",
"regionId": "",
"regionName": null,
"firstName": "Ivan",
"middleName": null,
"lastName": "Petrov",
"phone": "",
"email": "test@test.com",
"outerId": null,
"isDefault": false,
"description": null
}
}
]
We recommend to use JSON patch builders to simplify usage of PATCH https://json-patch-builder-online.github.io/