Servitly API Client

To interact with the Servitly backend API, you can leverage the ServitlyClient object, which is available in the JavaScript context.
It provides methods to retrieve, create, update, and delete data related to customers, locations, things, metrics, and more.

servitlyClient.getMeThings({}, function(things){
   // do stuff with the retreived things
}, function(error){
   console.error("Error retrieving things", error);
});

Filter Parameter

All methods accessing collections of objects, e.g. getMeThings(filter,....), require a parameter which is used to pass the conditions for filtering the requested objects.
Filter is a JSON object which can contain any of the following fields:

  • thingId: the identifier of the thing.

  • locationId: the identifier of the location.

  • customerId: the identifier of the customer.

  • parenThingId: the identifier of the parent thing.

  • query: the array of property-based conditions.
    [{"property": "name", "predicate": "eq", "value": "test"}, {...}]
    PREDICATES beginsWith, eq, neq, gt, gte, lt, lte, like, notLike, isEmpty, isNotEmpty.

  • limit: the maximum number of element to retrieve.

  • startDate: the start-date in milliseconds used to filter result elements by creation timestamp.

  • endDate: the end-date in milliseconds used to filter result elements by creation timestamp.

  • aggregation: the aggregation function and time frame to retrieve aggregated metric values (e.g. AVG_DAY_1).

Here is an example of filter parameter to retrieve things of a customer.

{
	"customerId": "1234567",
	"query": [
		{
			"property": "name",
			"predicate": "like",
			"value": "*XYZ*"
		}
	]
}

Callback Parameters

  • success: the callback called when the method successfully completes.
    This function receives the response object (e.g. thing JSON).

  • error: the callback called when the method invocation fails.
    This function receives the error details object.

In case you are using the ServitlyClient into a Promise, you can directly pass the resolve and reject callbacks.

new Promise(function (resolve, reject) {
     servitlyClient.getMeThings({}, resolve, reject); 
});

General Methods

With the following methods you can invoke any of the  Servitly backend API.  

doGet(endpoint, success, error)

Performs a GET request to the given endpoint.

doPost(endpoint, data, success, error)

Performs a POST request with payload data to the given endpoint.

doPut(endpoint, data, success, error)

Performs a PUT request with payload data to the given endpoint.

doGetFile(endpoint, success, error)

Performs a GET request to the given endpoint to retrieve a file.

doDelete(endpoint, success, error)

Performs a DELETE request to the given endpoint.

In addition to these methods, the ServitlyClient class provides more specific methods to interact with the main object types.

Thing Methods

getMeThings(filter, success, error)

Retrieves things visible by the logged-in user.

getThing(thingId, success, error)

Retrieves details of a thing by thingId.

saveThing(thing, success, error)

Creates or updates a thing with the given thing data.

Customer and Location Methods

getMeCustomers(filter, success, error)

Retrieves customers visible by the logged-in user.

getCustomer(customerId, success, error)

Retrieves a customer by customerId.

saveCustomer(customer, success, error)

Creates or updates a customer with the given customerdata.

getMeLocations(filter, success, error)

Retrieves locations visible by the logged-in user.

getLocation(customerId, success, error)

Retrieves a location by locationId.

saveLocation(customer, success, error)

Creates or updates a location with the given location data.

Metric Data Methods

getMetricValues(thingId, metricName, filter, success, error)

Retrieves the recorded values for the given thingId and metricName.

getLocationMetricValues(locationId, metricName, filter, success, error)

Retrieves the recorded values for the given locationId and metricName.

getMetricsLastValue(thingId, metricNames, success, error)

Retrieves the last recorded value for the given thingId and metricNames.

setMetricValue(thingId, metricName, ts, value, rollbackable, success, error)

Sets a value for the given thingId and metricName.

Statistics Methods

getStatisticData(parameters, success, error)

Compute and return the statistic value for the given parameters JSON object, which can contain any of the query parameters supported by the Statistics API endpoint.

Event and Work Session Methods

getActiveEvents(filter, success, error)

Retrieves active events.

getHistoricalEvents(filter, success, error)

Retrieves historical events.

getWorkSessions(filter, success, error)

Retrieves active work sessions.

getHistoricalWorkSessions(filter, success, error)

Retrieves historical work sessions.