Skip to main content

REST API Examples

This page provides practical examples for common REST API operations in Mango. All examples assume you have already authenticated (see Authentication) and are sending the appropriate session cookies and XSRF token headers with each request.

Reading Data Points

Retrieve a list of data points, optionally filtered using RQL:

# Get all data points (limited to first 100)
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/data-points?limit(100)"

# Get a specific data point by XID
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/data-points/DP_MyPoint_001"

# Filter data points by device name
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/data-points?eq(deviceName,HVAC%20Unit%201)&limit(50)"

# Search data points by name pattern
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/data-points?match(name,*Temperature*)&limit(50)"

Querying Point Values

Retrieve historical or real-time values for data points:

# Get the latest value for a data point by XID
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/point-values/latest/DP_MyPoint_001"

# Get multiple latest values
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/point-values/single/DP_MyPoint_001?from=2025-01-01T00:00:00.000-05:00&to=2025-01-02T00:00:00.000-05:00&limit(1000)"

# Get rolled-up values (e.g., hourly averages)
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/point-values/single/DP_MyPoint_001?from=2025-01-01T00:00:00.000-05:00&to=2025-01-02T00:00:00.000-05:00&rollup=AVERAGE&timePeriodType=HOURS&timePeriods=1"

Setting Point Values

Set values on settable data points:

# Set a numeric value
curl -b cookies.txt \
-H "X-XSRF-TOKEN: $XSRF" \
-H "Content-Type: application/json" \
-X PUT \
-d '{"dataType": "NUMERIC", "value": 72.5}' \
"http://localhost:8080/rest/latest/point-values/DP_Setpoint_001"

# Set a multistate value
curl -b cookies.txt \
-H "X-XSRF-TOKEN: $XSRF" \
-H "Content-Type: application/json" \
-X PUT \
-d '{"dataType": "MULTISTATE", "value": 2}' \
"http://localhost:8080/rest/latest/point-values/DP_Mode_001"

# Set a binary (boolean) value
curl -b cookies.txt \
-H "X-XSRF-TOKEN: $XSRF" \
-H "Content-Type: application/json" \
-X PUT \
-d '{"dataType": "BINARY", "value": true}' \
"http://localhost:8080/rest/latest/point-values/DP_Switch_001"

Setting Point Values from Custom Pages

When building custom Mango UI pages, you can set point values using the maPoint service in AngularJS. The ma-set-point-value component provides a ready-made UI control:

<ma-set-point-value
point="myPoint"
show-button="true"
set-on-change="false">
</ma-set-point-value>

For programmatic control from a custom component, use the point's setValue() method:

// In an AngularJS component controller
this.maPoint.get({xid: 'DP_Setpoint_001'}).$promise.then(point => {
point.setValue(72.5);
});

Managing Data Sources

# List all data sources
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/data-sources?limit(50)"

# Get a specific data source by XID
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/data-sources/DS_Virtual_001"

# Enable a data source
curl -b cookies.txt \
-H "X-XSRF-TOKEN: $XSRF" \
-H "Content-Type: application/json" \
-X PUT \
-d '{"enabled": true}' \
"http://localhost:8080/rest/latest/data-sources/enable-disable/DS_Virtual_001"

Querying Events

# Get active alarms
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/events?eq(active,true)&limit(100)"

# Get events by alarm level
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/events?eq(alarmLevel,CRITICAL)&limit(50)"

# Acknowledge an event by ID
curl -b cookies.txt \
-H "X-XSRF-TOKEN: $XSRF" \
-H "Content-Type: application/json" \
-X PUT \
"http://localhost:8080/rest/latest/events/acknowledge/42"

Managing Users

# List all users
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/users"

# Get the currently logged-in user
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/users/current"

Working with the JSON Store

The JSON store allows you to persist arbitrary JSON data, which is useful for storing dashboard configurations, custom settings, or application state:

# Read a JSON store item
curl -b cookies.txt -H "X-XSRF-TOKEN: $XSRF" \
"http://localhost:8080/rest/latest/json-store/myConfigItem"

# Create or update a JSON store item
curl -b cookies.txt \
-H "X-XSRF-TOKEN: $XSRF" \
-H "Content-Type: application/json" \
-X POST \
-d '{"xid": "myConfigItem", "name": "My Config", "jsonData": {"setting1": "value1", "setting2": 42}}' \
"http://localhost:8080/rest/latest/json-store"

JavaScript (Browser) Examples

When working within the Mango UI or custom pages, you can use the built-in AngularJS services:

// Using maPoint service to query data points
maPoint.buildQuery()
.eq('deviceName', 'HVAC Unit 1')
.limit(100)
.query()
.then(points => {
console.log('Found points:', points.length);
});

// Using maPointValues to get historical data
maPointValues.getPointValuesForXid('DP_Temperature_001', {
from: moment().subtract(1, 'day'),
to: moment(),
rollup: 'AVERAGE',
timePeriodType: 'HOURS',
timePeriods: 1
}).then(values => {
console.log('Values:', values);
});

Common RQL Operators Reference

When querying list endpoints, use these RQL operators in the query string:

OperatorExampleDescription
eqeq(name,Temperature)Equal to
nene(status,DISABLED)Not equal to
gtgt(value,100)Greater than
ltlt(value,50)Less than
gege(value,0)Greater than or equal
lele(value,100)Less than or equal
matchmatch(name,*Temp*)Wildcard match
inin(deviceName,Device1,Device2)In a set of values
limitlimit(10,20)Limit results (count, offset)
sortsort(name) or sort(-name)Sort ascending or descending
andeq(a,1)&eq(b,2)Logical AND (default)
oror(eq(a,1),eq(a,2))Logical OR

See the RQL Queries page for more details on query syntax.

  • REST API Authentication — Session, JWT, and CSRF token setup required before making requests
  • RQL Queries — Full reference for Resource Query Language operators
  • REST API Overview — Base URL, response format, and Swagger UI documentation
  • Custom Pages — Build UI pages that call the REST API with AngularJS services