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:
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
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.
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.
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
- equalsnot_eq
- not equalscontains
not_contains
eq_case
- case insensitive equalsnot_eq_case
contains_case
not_contains_case
present
- value is ignored in comparisonblank
- value is ignored in comparisonAlso 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
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.
Param name | Description |
---|---|
project_id required |
The project ID number Validations:
|
xml optional |
Returns sessions data as XML instead of as a JSON array. Validations:
|
uuids_only optional |
Returns an array of session uuids only. Validations:
|
Return the count all sessions in the project.
Use the ‘filter’ query parameter to filter the sessions in the database.
Param name | Description |
---|---|
project_id optional |
The project ID number Validations:
|
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.
Param name | Description |
---|---|
project_id optional |
The project ID number Validations:
|
id optional |
The UUID of the session to fetch Validations:
|
deleted optional |
Search on deleted sessions Validations:
|
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:
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.
Param name | Description |
---|---|
project_id required |
The project ID number Validations:
|
session[uuid] optional |
The UUID for the session. A random UUID will be created if none is supplied. Validations:
|
session[unit_id] required |
The UnitID for the device that created the session. Validations:
|
session[created] optional |
The unix timestamp for when the session was created. Defaults to the current time if not supplied Validations:
|
session[saved] optional |
The unix timestamp for when the session was saved. Defaults to the current time if not supplied Validations:
|
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:
|
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.
Param name | Description |
---|---|
project_id required |
The project ID number Validations:
|
id optional |
The UUID for the session. A random UUID will be created if none is supplied. Validations:
|
session[unit_id] optional |
The UnitID for the device that created the session. Validations:
|
session[saved] optional |
The unix timestamp for when the session was saved. Defaults to the current time if not supplied Validations:
|
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:
|
sessions required |
An array of sessions to update Validations:
|
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
.
Param name | Description |
---|---|
project_id optional |
The project identifier Validations:
|
id optional |
The UUID of the session Validations:
|
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.
Param name | Description |
---|---|
project_id optional |
The project identifier Validations:
|
session_id optional |
The UUID of the session Validations:
|
unit_id optional |
The Unit ID of the device that will receive the session. Validations:
|
session_type optional |
Determines if the original session or a new duplicate is sent. Options: ‘duplicate’ | ‘original’. Default: ‘original’ Validations:
|
include_sub_sessions optional |
Determines if sub sessions (from sub project) will be sent as well. Options: true | false. Default: false Validations:
|
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.
Param name | Description |
---|---|
project_id optional |
The project identifier Validations:
|
session_ids optional |
The UUIDs of the sessions Validations:
|
times_to_duplicate optional |
Determines how many times to duplicate the sessions. Default: 1 Validations:
|
include_sub_sessions optional |
Determines if sub sessions (from sub projects) will be sent as well. Options: true | false. Default: false Validations:
|