REST API Update Only Method (Patch?)


I noticed that using the “Patch” method when the resource does not already exist results in the resource being created (all fields not provided are set to the default). This is in a User Defined Table. My previous understanding of “Patch” was that I could expect an error if the resource doesn’t exist, and “Put” would be more of an “upsert” operation (update or insert if does not exist) which is consistent with the behavior I am getting out of “Patch” now. I see that there are no “Put” methods in the API and that “Patch” is the general update method. How do I only update resources of a UD table, receiving an error when the record does not exist?

A work around would be to query the table with a get, and only preform the patch if the record existed. Not sure your version, but I know they have done a lot of work on the REST interface.

1 Like

PUT also implies that complete object definition is sent, and with UpdateExt we use here, it is not a case. We only require key and changed fields.
For your task you have to do 2 calls - GET an PATCH

1 Like

Thank You @Olga @dpenn , I will use the two calls method.

What is the “key”? I’m getting a 400 error “The request is invalid.” no matter what I try. I’m using the API help page. I started with simply taking the data returned, updating the field in question, setting RowMod=“U” and then passing the results to the PATCH update. I tried several variations on RowMod and UD_SysRevID being present or not, as well as just including the modified field and these fields. I also tried including the primary key fields for the table.

RowMod is not relevant for OData, UpdateExt takes care of it.
What json you specify and what service you are testing

1 Like

Thanks, figured it out in another thread but it looks like I had too much data.