REST API: Cannot PATCH to an empty field

Kellen Fields
Kellen Fields
  • Updated

Author: Kellen Fields

Date: April 25, 2024

Audience:  Everyone

Summary: 

When using a PATCH REST API command to an empty field, you receive a bad request message back:

{
"meta": {
"status": "Bad Request",
"timestamp": "2024-04-07T17:51:18.034+0000",
"message": "no such path in target JSON document\n{\"op\":\"replace\",\"path\":\"/fields/method$89\",\"value\":\"test\"}"
}
}

And no update will take place.


Solution:

If the field is empty,  you will not be able to replace it using PATCH. Instead, you will have to use add:

Screenshot 2024-02-07 at 9.53.02 AM.png

{
"meta": {
"status": "OK",
"timestamp": "2024-04-07T17:53:20.841+0000"
}
}

Cause:

According to RF 6902, which we use for available changes with PATCH (https://datatracker.ietf.org/doc/html/rfc6902#section-4.1), it states for add
 
"If the target location specifies an object member that does not exist, a new member is added." 
 
Whereas replace states: 
 
"The "replace" operation replaces the value at the target location with a new value.  The operation object MUST contain a "value" member whose content specifies the replacement value."

 

Related to

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.