Getting a KiiObject

The Thing SDK Embedded can get a KiiObject by specifying its ID. By storing the ID of an existing KiiObject, you can later reference the KiiObject. See "Object ID and URI" (Android, iOS, JavaScript) for more information on the KiiObject ID.

Note that the Thing SDK Embedded does not directly support search with queries. However, you can search with queries by calling the REST API from the thing. See Executing REST API for sample code to search with queries using the REST API.

To get JSON data of a KiiObject, execute the kii_object_get function with the KiiObject ID specified.

/* Set the KiiObject ID. */

int ret;

/* Set bucket parameters. */
kii_bucket_t bucket;
memset(&bucket, 0x00, sizeof(kii_bucket_t));
bucket.scope = KII_SCOPE_THING;
bucket.bucket_name = "myBucket";
bucket.scope_id = "VENDOR_THING_ID:rBnvSPOXBDF9r29GJeGS";

/* Get the KiiObject. */
ret = kii_object_get(&kii, &bucket, OBJECT_ID);
if (ret != 0) {
  /* Handle the error. */

printf("object data:%s\n", kii.kii_core.response_body);

Specify the target bucket with the kii_bucket_t structure. See Creating a KiiObject to learn how to specify it.

The kii_core.response_body member of the kii_t structure stores the retrieved result. As seen in the sample code, you can get the JSON string by directly referencing this member.

You can use the kii_json library to get a value for a given key in the JSON string. See Parsing JSON to learn how to implement it.

See below for an example of an obtained KiiObject. Note that real messages will not have any carriage return.

  "_created": 1466154835092,
  "_modified": 1466154939409,
  "_owner": "th.727f20b00022-e1ba-6e11-42e2-08707492",
  "_version": "1",
  "power": true,
  "status": "NORMAL",
  "temperature": 25

Referencing predefined fields

Kii Cloud automatically sets values to these fields when a KiiObject is created. The JSON string includes these fileds when retrieved.

Key name Description
_id Object ID, which is automatically assigned or explicitly specified when the KiiObject is created. The ID value is guaranteed to be unique within the bucket. See "Object ID and URI" (Android, iOS, JavaScript) for more information.
_owner User or thing which creates the KiiObject. This field is especially referenced in the object ACL.
_created Time when the KiiObject is created in UNIX time (msec) in UTC.
_modified Last time when the KiiObject is updated in UNIX time (msec) in UTC. It has the same value as _created when the KiiObject is created.
_version Version number of the KiiObject. It is 1 when the KiiObject is created and incremented by 1 every time the KiiObject is updated. This field is used in the optimistic lock to detect update conflicts.