PATCHes in request inclusion
When using request inclusion, you can PATCH both root and included resources.
When PATCHing root resources using request inclusion, payloads generally have similar structures to POST payloads. For more information on payload structures, see Syntax for simple parent/child relationships and Syntax for named relationships.
However, when PATCHing, the uri field for included resources is treated
differently from POSTs.
The this keyword is invalid when
PATCHing
this keyword is a placeholder that is
only used when the id of the root resource has not yet been generated. If the root
resource is being PATCHed, its id has already been generated, so the use of
this results in an error. PATCHing parent and POSTing child
Here is the basic syntax for PATCHing a parent and POSTing a child.
{
"data" : {
"attributes": {
...
}
},
"included": {
"{resourceType}": [
{
"attributes": {
...
},
"method": "post",
"uri": "/../{parentId}/{resourceType}"
}
]
}
}
PATCHing parent and PATCHing child
Here is the basic syntax for PATCHing a parent and PATCHing a child.
{
"data" : {
"attributes": {
...
}
},
"included": {
"{resourceType}": [
{
"attributes": {
...
},
"method": "patch",
"uri": "/../{childId}"
}
]
}
}
uri field may or may not include a
placeholder for the parent id. It depends on the structure of the endpoint the uri
is referencing. uri fields would be:"uri": "/claim/v1/claims/{claimId}/contacts/{contactId}""uri": "/common/v1/notes/{noteId}"
Additional example of PATCHing in request inclusion
Below is an example of a payload in which the root resource is PATCHed and included resources are PATCHed and POSTed. This request performs the following actions:
- PATCHing a claim to set the main contact to an existing ClaimContact
- PATCHing a ClaimContact to add a cell phone number
- POSTing a note on the parent claim
PATCH http://localhost:8080/cc/rest/claim/v1/claims/demo_sample:2
{
"data": {
"attributes": {
"mainContact": {
"id": "cc:SF6434QkBBFpxqB1dQEcJ"
}
}
},
"included": {
"ClaimContact": [
{
"attributes": {
"cellPhone": {
"countryCode": {
"code": "US",
"name": "United States (1)"
},
"number": "123-456-7890"
}
},
"method": "patch",
"uri": "/claim/v1/claims/demo_sample:2/contacts/cc:SF6434QkBBFpxqB1dQEcJ"
}
],
"Note": [
{
"attributes": {
"subject": "Updated main contact",
"body":"Added Allen Robertson as main contact and updated his cell phone number."
},
"method": "post",
"uri": "/claim/v1/claims/demo_sample:2/notes"
}
]
}
}