A session is the same as a session on the mobile device.

Each session has a number of attributes associated with it that are common for each project, such as the Unit ID of the device that created the session, and a variable number of points according to the definition of the project at the time the session was created.

The JSON representation of the session will be an object with the following keys:

"uuid" : String, The session UUID
"unit_id" :  String, The Unit ID of the device that created (or last edited) this session
"created" :  String, The date and time the session was created
"created_timestamp" : Integer, The unix timestamp for when the session was created
"saved" :  String, The date and time the session was saved
"saved_timestamp" :  Integer, The unix timestamp for when the session was saved
"received" :  String, The date and time the session was received at the server (when the device submitted the session).
"received_timestamp" : Integer, The unix timestamp for when the session was received.
"received_from" : String, The username or device unit ID that created or most recently modified this session. This will be a User's username if the session was created/edited from the web portal or via the API and would be a device unit ID if created/edited via a device.
"is_deleted": Boolean, The status for the session. This will be true when the session has been deleted or false when the session is active.
"data" : object/dictionary, The values for the points in this session, see below for further notes.

The data values for point names are returned in an object as follows:

  • The point name is used as the key. This is always represented in lower case, which mirrors the internal implementation of Mobile Data mobile clients, and allows point names to be referred to in a case insentive manner by always converting point names to lower case.
  • The corresponding object (dictionary) value is the value of the point. Typically, all values are stored as strings. There may be some points, such as Sketch points that store binary data, or Camera points that store attached image files. These complex values are represented as an object(dictionary) with keys describing the file. This typically includes the name of the attached file, but will not normally contain the actual file data.

Time Zone Support

All values stored in the Mobile Data Anywhere database are UTC timestamps. These can be consistently converted to whatever timezone is required.

However, on the mobile client devices, the times are stored in the local time zone of the device. In order to know what the device’s local time zone is, the mobile devices store their local time zone offset in a hidden point named “timezone”. This value is used, if present to convert the created and saved dates into UTC and back again if sent to a device.

You can easily set this value when creating a session.

The value of the __timezone__ point is the number of seconds from UTC. For example, Brisbane Australia (+10 hours) would be 36000, and New York (-5 hours) would be -18000

Accessing Attachments

For points that contain attachments, the attached file can be accessed via the Attachments API calls. Attachments can be quite large and are stored separately to optimise session data access and filtering operations. This also allows API clients to cache attachments so that they do not need to be downloaded repeatedly, saving bandwidth and time.

Changing project definitions

The points stored in a session reflect the definition of the project at the time the session was created. Subsequently altering a project does not cause session values to be recalculated or populated with default values in the updated project.

Additionally, some points may not store a value at all if the page containing the point has never been accessed. Clients should always test for the presence of a point’s name in the “data” object. A missing key, key with a null value or a key with an empty string value should all be considered as having the same “empty” value.

Filtering results.

The index (get list) and count (get count) methods can apply a filter to the database and return the sessions, or count of sessions matching the filter.

The following filters can be applied in the query string:

  • received_since: A unix timestamp where only sessions received by the server after this time will be included.
  • skip: Skip a number of results in the get session list method (does not apply to count method).
  • limit: Return only this many results in the get session list method (does not apply to count method).
  • filter[unit_id]: Only sessions submitted by a specific unit id.
  • filter[received_from]: Only sessions that were last modified by the specified username or device unit id.
  • filter[Data.{point_name}]. Only sessions where the point named “point_name” will be included. Note that “Data” must have a capital D and the point name must be in lower case.

The “filter” keys also support a number of conditions, such as equals, not equals, contains, not contains, and case insensitive versions of these. There is also conditions to check for the presence or absence of a value for the given point. These filter conditions are used by constructing the query parameter like so:

  • filter[Data.{point_name}][{condition}] where {point_name} is the lower case point name, and {condition} is one of:
    • eq - equals
    • not_eq - not equals
    • contains
    • not_contains
    • eq_case - case insensitive equals
    • not_eq_case
    • contains_case
    • not_contains_case
    • present - value is ignored in comparison
    • blank - value is ignored in comparison

Also note that the square brackets need to be correctly URL encoded.

Example:

Filter by presence of a value in a the point “name” and the point “address” containing ‘Coast’ results in the following query string before URL escaping: ?filter[Data.name][present]=1&filter[Data.address][contains]=Coast

GET /api/v1/projects/1234/sessions?filter%5BData.name%5D%5Bpresent%5D%3D1%26filter%5BData.address%5D%5Bcontains%5D%3DCoast

GET /api/v1/projects/:project_id/sessions
Return a list of sessions in a project

Return a list of all sessions in the project.

Use the ‘limit’ and ‘skip’ query parameters to do range sub-queries. Use the ‘filter’ query parameter to filter the sessions in the database.

All session data is returned except for attachments. If you have many sessions, it may be better to make repeated calls to the server to fetch smaller amounts at a time.

Params

Param name Description
project_id
required

The project ID number

Validations:

  • Must be a Integer

xml
optional

Returns sessions data as XML instead of as a JSON array.

Validations:

  • Must be a Boolean

uuids_only
optional

Returns an array of session uuids only.

Validations:

  • Must be a Boolean


GET /api/v1/projects/:project_id/sessions/count
Return the count of sessions in a project

Return the count all sessions in the project.

Use the ‘filter’ query parameter to filter the sessions in the database.

Params

Param name Description
project_id
optional

The project ID number

Validations:

  • Must be a Integer


GET /api/v1/projects/:project_id/sessions/:id
Fetch the details of a session

Fetch a session from the database. For points that have an attached file, the value of the point will be a hash with a “filename” key with the filename of the attached file. Each attachment can be downloaded with an individual call to the attachments endpoint. This is to save bandwidth and time in case attachments do not need to be downlaoded multiple times.

This api call will return a 404 Not Found if the session does not exist.

On a successful call, a standard JSON response with the session data in the result.

Params

Param name Description
project_id
optional

The project ID number

Validations:

  • Must be a Integer

id
optional

The UUID of the session to fetch

Validations:

  • Must be a String

deleted
optional

Search on deleted sessions

Validations:

  • Must be a Boolean


GET /api/v1/projects/:id/sessions/:uuid/data


GET /api/v1/projects/:id/sessions/:uuid/s2c_packet


POST /api/v1/projects/:project_id/sessions
Create a new session in the database.

This api call creates a new session in the database.

If a UUID is supplied, any existing session with that UUID is deleted first. Otherwise, if no UUID is supplied One is created.

This api call accepts the following content-types:

  • application/json : The request body is interpreted as a JSON document. File attachments are not supported.
  • multipart/form-data : The request is interpreted as a standard web form post. File attachments are supported.
  • application/x-www-form-urlencoded: The request is interpretted as a form post. File attachments are supported.

For the form request types, attachments can be uploaded to the database at the same time as uploaded the session. The attachments must be in the correct field names to be recognised, as detailed below.

The request is expected to contain a structured document as follows:

JSON example:

{
  "session":{
    "uuid" : "12341234-12341234-1234-1234-123412341234",
    "unit_id" : "mydevice",
    "created" : 1234567890,
    "saved" : 1234567890,
    "data" : {
      "point1" : "value1",
      "point2" : "value2",
      "sketch1" : { "rawData" : "base-64-data-goes-here" }
    }
  }
}

For a form post the fields would be named:

session[uuid]=12341234-12341234-1234-1234-123412341234
session[unit_id]=mydevice
session[created]=1234567890
session[saved]=1234567890
session[data][point1]=value1
session[data][point2]=value2
session[data][sketch1][rawData]=base-64-data-goes-here==
session[data][__timezone__]=36000

A successful call will return a JSON response with the session data in the result.

Params

Param name Description
project_id
required

The project ID number

Validations:

  • Must be a Integer

session[uuid]
optional

The UUID for the session. A random UUID will be created if none is supplied.

Validations:

  • Must be a String

session[unit_id]
required

The UnitID for the device that created the session.

Validations:

  • Must be a String

session[created]
optional

The unix timestamp for when the session was created. Defaults to the current time if not supplied

Validations:

  • Must be a Integer

session[saved]
optional

The unix timestamp for when the session was saved. Defaults to the current time if not supplied

Validations:

  • Must be a Integer

session[data][<point_name>]
optional

The value for the point given by point_name. This can be a scalar value (string) or a hash with a rawData key for any small amount of embedded binary data. For attachments, this field will be an file uploaded in a mutipart form post.

Validations:

  • Must be a String


POST /api/v1/projects/:name/receive_raw_session
Receive a single session and process it as if it came from a device.


POST /api/v1/projects/:name/receive_raw_sessions
Receive a batch of sessions and process them as if it came from a device.


PUT /api/v1/projects/:project_id/sessions/:session_id
Update an existing session.

PUT /api/v1/projects/:project_id/sessions
Update multiple existing sessions.

This api call creates a new session in the database. The existing session is modified and only the provided values are updated in the existing session. All other values are left unchanged. This call accepts the same request body content-types as the Session create (POST) action. Attachments are handled in the same way.

Any attachments uploaded via this api call will replace existing attachments, which will be deleted once the new attachment is saved to the database.

This api call returns a 404 Not Found if the session does not exist in the database.

A successful call will return a JSON response with the session data in the result.

Params

Param name Description
project_id
required

The project ID number

Validations:

  • Must be a Integer

id
optional

The UUID for the session. A random UUID will be created if none is supplied.

Validations:

  • Must be a String

session[unit_id]
optional

The UnitID for the device that created the session.

Validations:

  • Must be a String

session[saved]
optional

The unix timestamp for when the session was saved. Defaults to the current time if not supplied

Validations:

  • Must be a Integer

session[data][<point_name>]
optional

The value for the point given by point_name. This can be a scalar value (string) or a hash with a rawData key for any small amount of embedded binary data. For attachments, this field will be an file uploaded in a mutipart form post.

Validations:

  • Must be a String

sessions
required

An array of sessions to update

Validations:

  • Must be an array of any type


DELETE /api/v1/projects/:project_id/session/:id
Delete a session from the database

The session will be deleted from the database, including any uploaded attachments.

This api call will return a 404 Not Found if the session does not exist.

On a successful call, a standard JSON response will be returned with a result of true.

Params

Param name Description
project_id
optional

The project identifier

Validations:

  • Must be a Integer

id
optional

The UUID of the session

Validations:

  • Must be a String


POST /api/v1/projects/:project_id/sessions/:session_id/deliver
Send this session to a device

The session will be sent to the device identified by its Unit ID. The session will remain in the database on the server. When the device sends the session back, the updated session will replace the record in the server database.

If the device is connected, the session will be sent immediately. Otherwise the session will be queued and sent to the device when it next connects.

Params

Param name Description
project_id
optional

The project identifier

Validations:

  • Must be a Integer

session_id
optional

The UUID of the session

Validations:

  • Must be a String

unit_id
optional

The Unit ID of the device that will receive the session.

Validations:

  • Must be a String

session_type
optional

Determines if the original session or a new duplicate is sent. Options: ‘duplicate’ | ‘original’. Default: ‘original’

Validations:

  • Must be a String

include_sub_sessions
optional

Determines if sub sessions (from sub project) will be sent as well. Options: true | false. Default: false

Validations:

  • Must be a Boolean


POST /api/v1/projects/:project_id/sessions/duplicate
Duplicate sessions

The sessions will be duplicated together with their attachments a number of times, once by default. Based on the parameters the sub sessions from sub projects can be included in the duplication process or not.

Params

Param name Description
project_id
optional

The project identifier

Validations:

  • Must be a Integer

session_ids
optional

The UUIDs of the sessions

Validations:

  • Must be a String

times_to_duplicate
optional

Determines how many times to duplicate the sessions. Default: 1

Validations:

  • Must be a Integer

include_sub_sessions
optional

Determines if sub sessions (from sub projects) will be sent as well. Options: true | false. Default: false

Validations:

  • Must be a Boolean