The Cloud has a public API that can be used to retrieve certain project-related data:
project ID, group, and KPIs;
tags and their history;
pages;
available timezones.
Tip
Visit our Swagger site to try the Cloud API; no code required!
Introduction
API usage requires at minimum three parameters:
Base URL Address of the server to send API requests to. For the Cloud, use the following base URL: https://energymachines.cloud/api/v1/
Access token Cloud API uses bearer authorization, which relies on a single string, referred to as access token, to authenticate the user. Contact EnergyMachines™ support to get an appropriate access token.
Tokens provide fine-grained access to specific projects/project data as configured when creating a token. API requests may result in an error if the token does not have sufficient access to retrieve the requested data.
Endpoint String appended to the base URL to specifically request particular data as discussed below. Base URL and endpoint together form the request body.
Basic syntax
This section demonstrates basic use of the Cloud API with the popular API library Python Requests.
Cloud API uses two request types:
requests are submitted with requests.get:
# prepare the requests lib
pipinstallrequests# unless already installed
importrequests# main API parameters
baseurl="https://energymachines.cloud/api/v1/"token="%YOUR_ACCESS_TOKEN%"# Refer to EM customer support
headers={"Authorization":f'Bearer {token}'}# request variables
pid="%PROJECT_ID%"# Target project ID
params={"tagPath":"%PATH/TO/TAG%"}# Query parameters
endpoint=f'{pid}/tag/by-path'# Endpoint with a URL parameter
# request
request=baseurl+endpoint# concatenate two strings to get the appropriate request URL
response=requests.get(request,headers=headers,params=params).json()
requests are submitted with requests.post and must be accompanied with a request body in the JSON format; see Parameters below:
# prepare the requests lib
pipinstallrequests# unless already installed
importrequests# main API parameters
baseurl="https://energymachines.cloud/api/v1/"token="%YOUR_ACCESS_TOKEN%"# Refer to EM customer support
headers={"Authorization":f'Bearer {token}'}# request variables
pid="%PROJECT_ID%"# Target project ID
data={"accessMode":"R","devicePathList":["Signals/DEVICE_01/"]}# Request body
endpoint=f'{pid}/tag/values/export/csv'# Endpoint with a URL parameter
# request
request=baseurl+endpoint# concatenate two strings to get the appropriate request URL
response=requests.get(request,headers=headers,json=data).text
Cloud API has only four URL parameters and uses them across multiple endpoints:
projectId — Target project ID, can be retrieved using the project list endpoint, among other means.
tagId — Target tag ID, can be retrieved using the tag list endpoint, among other means.
fileId — Target page ID, can be retrieved using the Tags endpoint, among other means.
format — Format for tag history export using the Tag History Requests endpoints; only has two possible values.
json for export in JSON format;
csv for export as a plain-text file containing comma-separated values.
URL parameters are used with both and requests.
Query parameters
Variables passed in dictionary, hash, or another object that can hold key-value pairs, and submitted as query parameters using the API library’s appropriate method:
Request body specifications are provided below in endpoint descriptions, which are structured as follows:
endpoint description
TYPEendpoint/with/{urlParams}
Description of data to be returned on such request. Required query parameters, if applicable.
Request body ( requests only):
{"key":"value"//requestbodyparameters}
Comments on the request body and its parameters.
CODE 200 Response format on a successfully processed API request:
{//"variable":"value"//Explanation}
for JSON response; or
String response
for string response, with additional commentary. Other response formats are covered individually.
CODE 404 (where applicable) Response on request failure due to incorrect URL parameters.
Code 404 error message (string)
Possible causes.
CODE 500 (where applicable) Response on request failure due to insufficient authorization or incorrect request body or query parameters.
{"status":"fail""error":"HTTP 403 Forbidden"}
Comments on error message codes.
URL parameters are curly-braced ({parameter}) in the endpoint syntax; however, the actual endpoint string must contain them without braces. Neither URL parameters nor query parameters are covered per endpoint. For details on parameters, see Parameters.
The following endpoints are available:
Project Requests
project list
projects/list
Returns an array of the projects the token is authorized to access.
accessMode selectively samples tags based on their writability and can take either of the two values:
R for read-only tags;
RW for writable tags.
Paths in the devicePathList array must be preceded with the prefix Signals/, for example: Signals/DEVICE_01.
Paths are not limited to devices and may also link to folders, see Tags for the tag hierarchy structure. To retrieve all tags from the root level down, provide Signals/ as the solitary path under devicePathList.
CODE 200
Tag Name,Tag Value
Signals/path/to/tag/name/name,current_value
Returns plain text (.txt) containing comma-separated values in two columns:
Tag Name — Full path to the tag, starting with the Signals/ prefix.
Tag Value — Tag value at the time of response generation.
groupingType — Value averaging timespan; accepted values are: MINUTES, HOURS, DAYS, MONTHS, YEARS. Default MINUTES returns data where each value is the average of all historical data points collected over a single minute, with the number of values matching the requested timeframe duration in minutes.
valueType (optional) — Determines the value calculation principle:
ACTUAL (default) returns actual values as grouped (averaged) by the period specified in groupingType;
DELTA replaces each value with the difference between it and the preceding value in the set.
tagList — Array of string representing tags for history export:
use tag ID with {projectId}/history/aggregate/by-id/{format};
use tag path with `{projectId}/history/aggregate/by-path/{format}.
timeFrom — Unix epoch timestamp, in milliseconds, for the starting point of the requested history sample.
timeTo — Unix epoch timestamp, in milliseconds, for the ending point of the requested history sample.
timeZone — (optional) Timezone to convert timestamps to, defaults to Europe/London. For list of available time zones, see Available Timezones.
time — Unix epoch timestamp of the datapoint, in ms.
tagId or id — ID of the processed tag.
name — tag path, inclusive of name (not custom).
unit — Displayed unit of the tag, if specified in the Tag Editor.
value — Tag value at the timestamp. In JSON response, unit and value parameters are grouped into the points array for each tag.
Timestamps in the response apply to value groups and thus may not correspond to the timestamps of any actual recorded data points. Timestamps for "groupingType":"DAYS" are matched to 00:00 GMT of the actual day in which the values were grouped.