PATCH

Updating specific parts of resources.

Our REST API uses the PATCH method to partially update resources, such as updating just the name of a contact.

📘

The PATCH method lets you update just part of a resource.

How to use PATCH

When making a PATCH request, include JSON Patch data in the body of your request, and "application/json-patch+json" as the value of your Content-Type header.

Example: Updating a Contact

In the example request below, we use cURL to update contact 1001's name.

curl --request PATCH https://restapi.rev.io/v1/Contacts/1001 \ 
--header "Content-Type: application/json-patch+json" \
--data "[{\"op\":\"replace\",\"path\":\"/name\",\"value\":\"Jane Smith\"}]"

Here's a better look at the JSON Patch data:

[
  {
    "op": "replace",
    "path": "/name",
    "value": "Jane Smith"
  }
]

We could also change this contact's mobile number in the same request, by adding that field to the JSON Patch data:

[
  {
    "op": "replace",
    "path": "/name",
    "value": "Jane Smith"
  },
  {
    "op": "replace",
    "path": "/mobile",
    "value": "5555551212"
  },
]

Example: Updating a custom field

Custom fields can also be updated via a PATCH request, with slightly different syntax.

The path of the PATCH would be: "fields/[Fields Array Index]/value" where the Fields Array Index is retrieved with a GET and is the index (starting at 0) of the desired field to be updated

"fields": [
    {
      "field_id": 1,
      "label": "Provider Number",
      "value": ""
    },
    {
      "field_id": 2,
      "label": "Service Type",
      "value": "Hosted PBX"
    },
    {
      "field_id": 4,
      "label": "Technician Name",
      "value": "John Smith"
    },
    {
      "field_id": 7,
      "label": "Identifier",
      "value": "B17649"
    }
  ]

Above we see that "Technician Name" is in the index place of 2, so to patch that field, we would use:

[
  {
    "op": "replace",
    "path": "/fields/2/value",
    "value": "Jane Smith"
  }
]

Similar to how we can update two parts of a contact, as shown above, we can also update two custom fields at once with the below syntax. Since "Technician Name" is in the index place of 2 and "Identifier" is in the index place of 3, we would use:

[
  {
    "op": "replace",
    "path": "/fields/2/value",
    "value": "Jane Smith"
  },
  {
    "op": "replace",
    "path": "/fields/3/value",
    "value": "A13695"
  }
]