Update a profile
Unlike a PUT
request, a PATCH
request will update only a portion of a recipient's profile. PATCH
syntax is a little more complicated. Courier uses the JSON Patch syntax described below.
Imagine that we have a profile with an email
and phone_number
. We want to update only the email address.
"profile": {
"email": "normanosborn@oscorp.com",
"phone_number": "555-555-5555",
}
Our patch request body will be JSON. The first key in a JSON Patch object will be op
, which stands for the operation you are to perform. This is assigned a value of add
, remove
, replace
, move
, copy
, or test
. We already have an email address present, so we will use replace
.
We list the value to be replaced by pointing to it using the path
key. This path
takes a value pointing to the key we want to target. The path is built using "/" characters. Our email
key is one level deep, so we will use "/email"
. We then have a value
key that is assigned the value we want to replace our existing email with. The entire line looks like this:
{ "op": "replace", "path": "/email", "value": "test@example.com" }
To send the PATCH
request, we send an array with our JSON Patch objects.
[{ "op": "replace", "path": "/email", "value": "test@example.com" }]
If you want to update multiple values, your patch will look like this:
[
{ "op": "replace", "path": "/email", "value": "test@example.com" },
{ "op": "replace", "path": "/phone_number", "value": "test@example.com" }
]
More Examples
The following types of requests will not change the body of an existing Profile:
// Empty Patch Array
{
"patch": []
}
The above will result with:
{
"status": "SUCCESS"
}
info
For more details about JSON Patch syntax:
Example
Method: PATCH
URL: https://api.courier.com/profiles/abcdefgh12345678
Body:
{
[
{
"op": "replace",
"path": "/email",
"value": "test@example.com"
},
{
"op": "add",
"path": "/phone_number",
"value": "1234567890"
}
]
}