Sending Event Data from the Mobile App

When uploading Event Data directly via REST API, you need to define the following properties together with your Event Data key-value pairs:

  • _type ... String value defining the event type (optional). You can specify any string like "installed" or "level up". When you specify "Filter by type" section during your Metric definition, this event type value will be used to filter the target data.
  • _deviceID ... String value uniquely identifying the source device.
  • _triggeredAt ... Long value specifying the time when the event has occurred (UNIX time in msec, UTC).
  • _uploadedAt ... Long value specifying the time when the event was uploaded (UNIX time in msec, UTC).

Your Event Data key-value pairs can be anything, provided that they follow these rules:

  • Key name must be between 1 to 64 characters (UTF-8).
  • Value should be of JSON number, string, boolean, or array.
    • Value cannot be null or empty.
    • Array values must be of JSON number, string, or boolean.
    • Number can have up to 38 digit precision and can be between 10^-128 to 10^126.
  • Cumulative size of key-value pairs should not exceed 2 KB (UTF-8).

When uploading Event Data, you can either upload single event one at the time, or you can upload multiple event data at once.

Here is an example of uploading single event:

curl -v -X POST \
  -H "Authorization: Basic {BASE64_ENCODED_APPID_AND_APPKEY}" \
  -H "Content-Type: application/vnd.kii.EventRecord+json" \
  "{APP_ID}/events" \
  -d '{"_type": "MyUser", "_deviceID": "DEVICE_ID", "_triggeredAt": "1350450764053", "_uploadedAt": "1350450764053", "gender": "M", "city": "San Francisco", "location": "USA", "children": 2, "age": 35}'

You can also send multiple events at once like the following example:

curl -v -X POST \
  -H "Authorization: Basic {BASE64_ENCODED_APPID_AND_APPKEY}" \
  -H "Content-Type: application/vnd.kii.EventRecordList+json" \
  "{APP_ID}/events" \
  -d '[ {"_type": "MyUser", "_deviceID": "DEVICE_ID", "_triggeredAt": "1350450764053", "_uploadedAt": "1350450764099", "gender": "M", "city": "San Francisco", "location": "USA","children": 2, "age": 35}, {"_type": "MyUser", "_deviceID": "DEVICE_ID", "_triggeredAt": "1350450764100", "_uploadedAt": "1350450764183", "gender": "F", "city": "San Francisco", "location": "USA", "children": 0, "age": 12} ]'

In both caese, you upload events with Basic Authentication. Replace {BASE64_ENCODED_APPID_AND_APPKEY} with a Base64-encoded string of concatenated AppID and an arbitrary value with a colon (:) in between the two values.