Full Update with the Overwrite Check

This method overwrites the data on the server with the key-value pairs sent from the client (the data on the server will be lost).

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 PUT \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  -H "Content-Type: application/vnd.{APP_ID}.mydata+json" \
  -H "If-Match: {OBJECT_VERSION}" \
  "https://api-jp.kii.com/api/apps/{APP_ID}/users/me/buckets/{BUCKET_ID}/objects/{OBJECT_ID}" \
  -d '{"score": 2300, "name": "game1"}'

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 fully updated, Kii Cloud will respond with the modification time in UNIX time (msec, UTC) like this:

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< ETag: "2"
< Content-Type: application/vnd.kii.ObjectUpdateResponse+json
< Transfer-Encoding: chunked
< Date: Mon, 14 May 2012 23:50:48 GMT
<
{
  "modifiedAt" : 1337039448517
}