A short guide to the Realiteq API
Introduction to using the RealiteQ API
The Realiteq API is HTTP-based. All interaction with the platform is done over HTTP/S. For better security, it is recommended that all requests are performed over HTTPS (encrypted connection).
1. Introduction
1.1 Conventions
All requests should be made to the domain name for the client's project, e.g.
https://myproject.realiteq.net/
Parameters should be passed as URL parameters.
Parameters should be URL-encoded.
The type of API call is passed using the
q
parameter, e.g.:https://myproject.realiteq.net/?q=open
The session key is passed using the
skey
parameter (see below.)The Realiteq server responds to all API calls with a JSON response containing at least one field, the
result
field. An"OK"
value signifies a successful API request:
An error response will include an error code in the `result` field, and a message:
Currently the Realiteq platform accepts requests on both HTTP and HTTPS. We will eventually accept API requests only on HTTPS.
2. Sessions
A session is a context object used to perform various API calls. The session is used to identify the user on which behalf the API is called, and the appropriate permissions. It is also used as a context for subscribing to state changes and providing events to reflect those changes.
Sessions are identified by a session key - skey
for short, a random string of 32 characters. Sessions are meant to be short-lived and will be discarded by the server if not used for 10 minutes.
2.1 Opening a session
To open a session use the open
query.
Parameters:
q
:open
u
: user name (optional)p
: password (optional)
(The user credentials are optional. If no user credentials are specified, the session will use the default permissions.)
Example request:
Response fields:
skey
: session keyuser
: the user nameuser_title
: proper name for the useruser_rules
: a list of access rules associated with the specified user.
Example response:
2.2 Closing a session
To close a session use the `close` query.
Parameters:
q
:close
skey
: session key
Example request:
Example response:
2.3 Subscribing to events
To receive state change events, a subscription should be made. A subscription is made to a discrete node in the node tree, and provides events only for that specific nodes. Events for any sub-nodes need to be subscribed to separately.
Parameters:
q
:sub
skey
: session keynodes
: a list of node paths, separated using!
Example request:
Subscribing to a single node can alternatively be done by specifying the node path in the URL path, e.g.:
Example response:
2.4 Unsubscribing
To stop receiving state change events for a specific node, use the unsub
query.
Parameters:
q
:unsub
skey
: session keynodes
: a list of node paths, separated using!
Example request:
Unsubscribing from a single node can alternatively be done by specifying the node path in the URL path, e.g.:
Example response:
2.5 Receiving events
Events can be received by using the events
query. Depending on the various request parameters, the server can block the response until a timeout has elapsed or events are available. The server can also stream events as they become available. In addition to the plain JSON response, the server can also provide streaming events using the SSE standard (Server-Sent Events).
Parameters:
q
: eventsskey
: session keym
: query mode:simple
,block
orstream
. The default issimple
t
: timeout in secondsk
: keep-alive frequency in seconds
Simple mode
When using the simple
mode, the server responds *immediately* with any pending events:
Example response (see discussion of event fields below):
Blocking mode
When using the block
mode, the server will block until an event is generated for the client's session. If no event is available within the specified timeout period, the server responds with an empty list of events:
Example response:
Receiving events using SSE (Server-Sent Events)
To receive events using SSE, the following parameters should be specified:
q
:events.sse
skey
: session keyt
: timeout in secondsk
: keep-alive frequency in seconds
An example for setting up a Javascript EventSource
:
Event fields
kind
: kind of event:101
: state change
path
: path of nodequality: quality of node value:
0
: unknown value1
: good value2
: bad value3
: invalid value4
: simulated value5
: forced value
stamp
: time stamp in Unix epoch secondsvalue
: value of nodeunformatted_value
: value of node without formattingdatatype
: data type:0
: text value1
: integer value2
: float value3
: boolean value
3. Nodes
Nodes are objects having distinct states and arranged in a hierarchical tree. A node may be a group (a container of child nodes), a point (representing a process value), or an alarm (representing a process alarm). A node is referenced by a path specifying its location in the node tree, with levels separated using a slash, e.g. /unit1/values/v1
.
Each node has its own attributes which affect its behaviour, and a state. A node's state represents an observed value or a calculated value derived from observed values. The state will include a quality field denoting the reliability of the measurement (for example, when no communication to the source of the value, for example a PLC, is possible, the quality will be set to 'bad'), a stamp denoting the time the observation was made, a value, and the value's data type (integer, floating-point number, boolean or text).
Node states can be optionally recorded to history, and can thereafter be queried in order to monitor value changes over time.
3.1 Querying real-time node states
To query the current state of a node, use the state
query. The response can be rendered in JSON or XML. The path part of the URL represents the node to query. Querying for multiple nodes at once is possible by using the nodes
parameter as described below.
The response will include for each specified node the following attributes:
quality
: an integer signifying a state class:0
: unknown1
: good2
: bad (usually meaning error in acquiring value from PLC)3
: invalid (usually meaning the node is not known by either PLC, iCEX or server)4
: simulated5
: forced
stamp
: a Unix time stampvalue
: the node's valueunformatted_value
: the node's value without formattingdatatype
: an integer signifying the datatype:0
: text1
: integer2
: floating-point number3
: boolean
Parameters:
q
:state
f
: the format to use for the response, one ofjson
,xml
(default:json
)nodes
: optional parameter for querying history for multiple nodes. nodes paths are separated using an exclamation mark and are relative to the path given in the URL. For example,v1!v2
tag
: optional parameter for selecting nodes by tagnames. Tagnames are separated using an exclamation mark. Tagnames will be searched among subnodes of the specified path.
Example request:
Example response:
3.2 Querying historical node states
To query node values, use the history
query. The response can be rendered in a number of different formats: JSON, XML, CSV or PDF.
The path part of the URL represents the node to query. Querying for multiple nodes at once is possible by using the nodes
parameter as described below.
Parameters:
q
:history
f
: the format to use for the response, one ofjson
,csv
,xml
,pdf
(default:json
)nodes
: optional parameter for querying history for multiple nodes. nodes paths are separated using an exclamation mark and are relative to the path given in the URL. For example,v1!v2
t1
,t2
: historical time range start and stop in unix epoch integer values-period
: alternative time range expressed in seconds counting back from the present moment, e.g.86400
will limit the query to the last 24 hours
The response will contain a list of historical states within the period defined using the t1
and t2
parameters, or alteratively the period
parameter.
Example request:
Example response:
Getting history for multiple nodes in tabulated form
Historical values can also be retrieved in a sort of 'pivot table', with a separate column for each node. To retrieve historical values in tabulated mode, add the following parameter:
- table
: 1
For example, the following query:
will get the following response:
Getting historical values at regular intervals
Historical values can also be retrieved at regular intervals of time, instead of the proper time at which they were observed. In this mode of retrieval, called _interpolated_ mode, the Realiteq platform provides the last known state of the relevant node or nodes at regular intervals.
To retrieve a node's historical states in interpolated mode, add the following parameters:
interpolate
:1
interval
: the interval in seconds (for example,3600
for intervals of 1 hour)
When retrieving history for multiple nodes in interpolated mode, the tabulated mode is implied, that is values will always be provided in tabulated form.
Example:
Example response:
3.3 Using web hooks to receive state updates
In addition to using sessions and events to receive state updates, nodes can be configured to send updates whenever the node's state is updated. The updates are sent using HTTP/S to a server provided by the client.
To configure remote updates, use the Realiteq web interface. For each node for which remote update is desired, set the remote update field to the URL of your server.
State updates will be sent as HTTP POST
requests with the following fields in URL encoding:
q
:remote_update
path
: the node pathquality
: quality of state (0
- unknown,1
- good,2
- bad,3
- invalid,4
- forced,5
- simulated)stamp
: time stamp in string formatraw_stamp
: time stamp in unix epochvalue
: the valueunformatted_value
: the value without formattingdatatype
: the data type (0
- text,1
- integer,2
- floating point,3
- boolean)
Last updated
Was this helpful?