TAHMO Server API
This article details where and how to use the documentation for the TAHMO server API.
Documentation (TAHMO server)
https://tahmo.zentracloud.com/api/v4/documentation/
Call limits
Users are limited to a total of 60 calls per minute(60sec), and each device is limited to 1 call per minute(60sec). One user can make 60 calls to 60 different devices in a 60-second period.
Token
- Select API.
- Click Copy token.
Test
Authorize
- Select Authorize.
- Paste token ID.
- Click Authorize.
GET request
To view examples press the GET readings button.
Parameters
Experiment with different start_date, end_date, or start_mrid and end_mrid query parameters. Only start_date and end_date or start_mrid and end_mrid parameters need to be defined in the request, not both. MRID stands for "Measurement Record ID" and increases as the number of records on the device increases.
Response format
Select the output_format. Options include json, pandas dataframe or csv.
Examples
View examples in json, csv or pandas Dataframe.
Units
To set the units, log in to your account at tahmo.zentracloud.com, click the wrench icon from the main menu, and select Measurement Units. Edit your preferred units and click Accept. See Setting your preferred measurement units article here.
Example Code Snippet
Copy the code snippet below, then edit the token tok
, device serial number sn
, and start and end dates start_date
, end_date
.
import requests # pip install requests
import pandas # pip install pandas
def get_with_credentials(tok, uri, **kwargs):
# just in case we forget to put "Token MyToken"
token = tok if tok.lower().startswith("token") else f"Token {tok}"
headers = {"Authorization": token}
return requests.get(uri, headers=headers, **kwargs)
def get_readings_response(sn, start_date, end_date, **extra_kwargs_for_endpoint):
server = extra_kwargs_for_endpoint.get("server", "https://zentracloud.com")
url = f"{server}/api/v4/get_readings/"
default_args = {
'output_format': "df",
'per_page': 1,
'page_num': 1,
'sort_by': 'desc',
'start_date': start_date,
'end_date': end_date
}
data = {**default_args, **extra_kwargs_for_endpoint, "device_sn": sn}
tok = extra_kwargs_for_endpoint.pop("token", "")
return get_with_credentials(tok, url, params=data)
def get_readings_dataframe(sn,start_date,end_date,**extra_kwargs_for_endpoint):
res = get_readings_response(sn,start_date,end_date,**extra_kwargs_for_endpoint)
if(res.ok):
data = res.json()
return pandas.DataFrame(**json.loads(data["data"]))
return res
#fill in your token, device serial number and start and end dates here.
tok = "Token <Your Token>"
sn="z6-#####"
start_date="2024-04-01 00:00:00"
end_date="2024-04-02 00:00:00"
#specify the server here.
server="https://tahmo.zentracloud.com"
df = get_readings_dataframe(sn, start_date, end_date, token=tok, server=server)
print(df)