Partial Update with the Overwrite Check

This method merges the data on the server with the key-value pairs sent from the client. You will send only key-value pairs you want to update from the client to the server. Note that you cannot delete the keys on the server with this method.

This method checks for overwrites using a technique known as optimistic locking. If the data on the server has been updated by other clients after you got the KiiObject, your update is rejected with an error.

Here is the sample code:

curl -v -X POST \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  -H "If-Match: 2" \
  -H "X-HTTP-Method-Override: PATCH" \
  "https://api-jp.kii.com/api/apps/{APP_ID}/users/me/buckets/{BUCKET_ID}/objects/{OBJECT_ID}" \
  -d '{"score": 5000}'

Notice that "X-HTTP-Method-Override: PATCH" header is sent. This header makes the KiiObject updated partially.

Sending the "IF-Match" header let the server check if the target KiiObject has been updated by other clients. If you want to update the KiiObject unconditionally, do not send the "IF-Match" header.

The value to send with the "IF-Match" header, {OBJECT_VERSION}, is the value of the _version field that was obtained last time. When you get a KiiObject by following the steps described in Getting a KiiObject, you will get JSON data like the following. Send the value specified in the _version field when you update the KiiObject next time. In this case, you will send "IF-Match: 3".

{"score":5000,"name":"game1","_created":1337039114613,"_id":"d8dc9f29-0fb9-48be-a80c-ec60fddedb54","_modified":1337040183711,"_owner":"ff43674e-b62c-4933-86cc-fd47bb89b398","_dataType":"mydata","_version":"3"}

Kii Cloud will compare the value of the _version field on the server with the value specified in the "IF-Match" header. If they differ, the server will respond with the HTTP status 409 to notify that the target KiiObject has been updated by another client.

If the KiiObject is partially updated, Kii Cloud will return a response like the following with the created and modified time in UNIX time (msec) in UTC.

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< ETag: "3"
< Content-Type: application/vnd.{APP_ID}.mydata+json
< Transfer-Encoding: chunked
< Date: Tue, 15 May 2012 00:03:03 GMT
<
{
  "score":5000,
  "name":"game1",
  "_created":1337039114613,
  "_id":"d8dc9f29-0fb9-48be-a80c-ec60fddedb54",
  "_modified":1337040183711,
  "_owner":"ff43674e-b62c-4933-86cc-fd47bb89b398",
  "_dataType":"mydata",
  "_version":"3"
}

The score field now has a value of 5000.